K
Kinde6mo ago
NewbBtw

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
NewbBtw
NewbBtwOP6mo ago
I am open to answe any questions needed to help with supporting me on this matter, thanks
Oli - Kinde
Oli - Kinde6mo ago
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:
KINDE_DEBUG_MODE = true;
KINDE_DEBUG_MODE = true;
Check Environment Variables Ensure that all required environment variables are correctly set in your live environment. These include:
KINDE_SITE_URL=https://${process.env.VERCEL_URL}
KINDE_POST_LOGOUT_REDIRECT_URL=https://${process.env.VERCEL_URL}
KINDE_POST_LOGIN_REDIRECT_URL=https://${process.env.VERCEL_URL}/dashboard
KINDE_SITE_URL=https://${process.env.VERCEL_URL}
KINDE_POST_LOGOUT_REDIRECT_URL=https://${process.env.VERCEL_URL}
KINDE_POST_LOGIN_REDIRECT_URL=https://${process.env.VERCEL_URL}/dashboard
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:
import {getKindeServerSession} from "@kinde-oss/kinde-auth-nextjs/server";
import {someUpdateFunction} from "@/app/actions";
const {refreshTokens} = getKindeSeverSession();
await someUpdateFunction({
param_1: "value_1",
param_2: "value_2"
});
await refreshTokens();
import {getKindeServerSession} from "@kinde-oss/kinde-auth-nextjs/server";
import {someUpdateFunction} from "@/app/actions";
const {refreshTokens} = getKindeSeverSession();
await someUpdateFunction({
param_1: "value_1",
param_2: "value_2"
});
await refreshTokens();
If these steps don't resolve the issue, let me know.
NewbBtw
NewbBtwOP6mo ago
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
Oli - Kinde
Oli - Kinde6mo ago
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
NewbBtw
NewbBtwOP6mo ago
Thanks Oli, for the reaching out @Oli - Kinde
Want results from more Discord servers?
Add your server