GetUser() returning Null on Live Nextjs.
Hi all i am hoping anyone could help me with this query.
I have a Nextjs14 application using Kinde Auth. It was working fine, but I woke up to a random bug on live. getUser is reutuning null only on live.
const { getUser } = getKindeServerSession()
const user = await getUser()
console.log("fetching user", user)
const ADMIN_EMAIL = process.env.ADMIN_EMAIL;
if (!user || user.email !== ADMIN_EMAIL) {
return notFound();
}
inside by dashboard route i have this logic to get the currently logged in user, but i have come to notice that getUser is returning null and this only happens on live. Does anyone else have this issue and how did they go about fixin it?5 Replies
I am open to answe any questions needed to help with supporting me on this matter, thanks
Hey @NewbBtw,
The
getKindeServerSession
helper is used to get an authorized user's Kinde Auth data from any server component. The getUser
method is one of the methods provided by this helper to get the current user's details.
However, if getUser
is returning null only in the live environment, it could be due to several reasons:
Debug Mode
First, you might want to enable debug mode to get more logs in your console that may help with debugging. You can do this by adding the following to your .env
file:
Check Environment Variables
Ensure that all required environment variables are correctly set in your live environment. These include:
Refresh Tokens
If the issue persists, you might need to refresh the tokens to get up-to-date Kinde data. You can use the refreshTokens
method provided by getKindeServerSession
:
If these steps don't resolve the issue, let me know.Thanks I’ve been able to solve this issue, I had written the application a while back using api/auth/login as the link to sign users in but I checked the docs and that has been updated to now use the <LogingLink>
Using that instead helped fixed the problem returning user in both live and dev mode
Good to know the issue is fixed.
Thanks for letting me know @NewbBtw.
Please don't hesitate to reach out and open a new #💻┃support thread if you come across any other issues
Thanks Oli, for the reaching out @Oli - Kinde