Next.js Discord

Discord Forum

Refreshing authentication status on navbar

Unanswered
Mugger Crocodile posted this in #help-forum
Open in Discord
Mugger CrocodileOP
I am refreshing my knowledge of next.js after quite a while and recently updated it to v16. I have currently enabled react compiler, cache components, and typed routes in the config.

I am creating a todo app for this purpose that has authentication, which is JWT based. When i retrieve the session through cookies and my database, I used React 19's cache() function and make the necessary database/function calls. To perform logins, I use a server action that redirects the user to the dashboard when successful, but fails to update the session UI data (like username display and links) after the redirect. This worked in next.js 15, but does not work now.

What could be the reasons for this?

GitHub link: https://github.com/kkapoor15904/todo-app-nextjs16

31 Replies

" I use a server action that redirects the user to the dashboard when successful, but fails to update the session UI data"

did u try calling refresh()?
after everything is done in server action
did u use unstable_cache or "use cache"?
can you send which files are relevant to the issue?
Mugger CrocodileOP
I tried calling refresh(), yes
‘Use cache’
@Mugger Crocodile ‘Use cache’
i need more information, such as how you read the session and how you set the sesison
Mugger CrocodileOP
Just a minute
This is the login sserver action
whats inside authClient?
you need to do debugging
console.log at each part of the getCurrentUser to see what went wrong
why it returned null
Mugger CrocodileOP
It is an instance of a custom package of mine, which for sure works
to handle authentication with JWT
Because I console.log the output of the function, and returns the correct value in the console, but does not update the UI
this is weird. can you reproduce it in a minimal repository?
Mugger CrocodileOP
I will try to do it
Mugger CrocodileOP
So I just tried doing it, and looks like the problem is with cacheComponents
I obviously had to try it out when it became stable in this version
Mugger CrocodileOP
Based on what I saw, it was prerendering the navigation bar
as soon as i disable cache components, it works just fine
@alfonsüs ardani this is weird. can you reproduce it in a minimal repository?
Mugger CrocodileOP
i reproduced it in a minimal repository too
even though "SessionContainer" is supposed to be dynamic, react is prerendering it for some reason
This is after prepending my component code with await connection()
Looks like cacheComponents still has a lot of stuff to work on
Curious to see how that is possible
hard to imagine how you did it