next.js server => api

Hi, I’m working on a smaller project with some friends for planning our board game events. I’m in the middle of doing some auth when connecting my next.js server component with my next.js api, and I’m unable to use getKindeServerSession to get a valid session? The request when doing the original fetch is authenticated. What do you need to know to show me the way? 👀
9 Replies
CB_Kinde
CB_Kinde3mo ago
Hi @VeryGingerBear Are you using the Next.js SDK? If so what version?
VeryGingerBear
VeryGingerBearOP3mo ago
Hi, I'm using the Next.js SDK, "@kinde-oss/kinde-auth-nextjs": "^2.3.6" I'm using App Router. I am doing a fetch request from my server component, which is able to get the authenticated user.
const { isAuthenticated } = getKindeServerSession();
const isAuth = await isAuthenticated();
//User is authenticated here.
if (!isAuth) {
return null;
}

const events = await getEvents();
const { isAuthenticated } = getKindeServerSession();
const isAuth = await isAuthenticated();
//User is authenticated here.
if (!isAuth) {
return null;
}

const events = await getEvents();
In the API route that this fetch call goes to I do not get a user.
export async function GET(req: NextRequest) {
const { getUser, isAuthenticated } = getKindeServerSession(req);
const isAuth = await isAuthenticated();
const user = await getUser();
export async function GET(req: NextRequest) {
const { getUser, isAuthenticated } = getKindeServerSession(req);
const isAuth = await isAuthenticated();
const user = await getUser();
I haven't found documentation on how the fetch request should be structured, if the Bearer token should be passed explicitly or not etc.
CB_Kinde
CB_Kinde3mo ago
Hi @VeryGingerBear just wondering if you tried Sam's recommendations, and if it worked?
VeryGingerBear
VeryGingerBearOP3mo ago
I tried adding debug, other than that I think the code above is pretty close?
CB_Kinde
CB_Kinde3mo ago
Sorry, which code? Are you still not getting the user?
VeryGingerBear
VeryGingerBearOP3mo ago
Two messages above? Can’t you see that message?
CB_Kinde
CB_Kinde2mo ago
Hey @VeryGingerBear very sorry I have let this thread go stale. I'm hoping you have solved the issue. If not please let me know where things are at and I'll revive efforts to resolve.
VeryGingerBear
VeryGingerBearOP4w ago
Switched to Clerk and solved the issue in a total of 10 minutes. Switch included.
CB_Kinde
CB_Kinde4w ago
Happy for you. Best of luck.
Want results from more Discord servers?
Add your server