Next.js Discord

Discord Forum

Session info from AuthJs not updating in base layout.tsx after a user logs in, but updates on refres

Unanswered
Spectacled bear posted this in #help-forum
Open in Discord
Spectacled bearOP
Hey all, dealing with something a little tricky. I have a reference to an Authjs session object in my app's RootLayout component:
const session = await auth();
  const emailAddress = session?.user?.email
    ? session.user.email
    : "Not Logged In";

When visiting the site not logged in (auth) routing, the appropriate value is logged. Once logged in, and the user is redirected to the authorized route (main) routing I would expect this value to update to reflect the user's info, but "Not Logged In" is still logged. If I refresh the page, or navigate to certain other pages, it does update. But upon redirect to / after a successful login, "Not Logged In" is still being logged.

I've tried to implement revalidatePath, but nothing seems to work. Am I missing something obvious?

0 Replies