Next.js Discord

Discord Forum

How to trigger re-render or page reload for server components

Unanswered
Stephen Strange posted this in #help-forum
Open in Discord
I have a server component as attached. The content of the page is dependent on “session” from next-auth’s getServerSession, it is basically a user’s profile page.

When I sign out, next-auth seems to reload the page so the heading tag “You are not signed in” gets displayed, but if I now sign back in, no page reload gets triggered so the heading stays instead of rendered the user’s profile content.

I wanted to know if there is a way to trigger reload of the page on server side or any other solution i’m not aware of inorder to detect this change in session, on the server side.

Currently I am using a temporary solution by having a useEffect in a client component, that listens for changes in “session” and then I call router.refresh(), but I want to know if there is a better solution out there, thanks.

2 Replies

Turkey Vulture
Hey @Stephen Strange were you able to find a solution?
I did my own cheesy solution, I have a context layer for authentication. In there I basically combine the server session with the client session by doing,
const session = serverSession ?? clientSession.
So that incase serverSession doesn’t reload then the client session takes over