Server-side vs client-side authentication with Next-auth (caching) #10435
Unanswered
codinginflow
asked this question in
Help
Replies: 1 comment 3 replies
-
Then it ends up becoming a mess, created some projects testing auth v5 and as soon as you use something inside the header that uses (await auth() from v5) all routes belonging to the layout become dynamic and the cache no longer works. Which basically takes away one of the fundamental features of nextjs such as (revalidate). Have you come up with any solutions for this with Auth v5? |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I need some clarification here.
Let's say I want to display the currently logged-in user in the navbar.
If I fetch the session server-side (
getServerSession
or now justawait auth()
in v5), all pages that display this navbar are dynamically rendered. There is no way to statically cache them anymore, correct?Considering this, would it make sense to move the session retrieval client-side, if I want to enable static caching? This would be done by wrapping the layout into a
SessionProvider
, not passing asession
prop, and then retrieving the session viauseSession
inside the navbar.Am I missing something? Like another better option? Or any caveats about my approach?
Beta Was this translation helpful? Give feedback.
All reactions