Layout component re-render after middleware signOut and redirect
Unanswered
Yellow-faced Grassquit posted this in #help-forum
Yellow-faced GrassquitOP
Hi there,
I've started working on a starter project in NextJs, using AuthJs as the authentication library. Everything is working well, and I've implemented database-level session checking in the middleware. I'm accessing the database with Drizzle ORM. The middleware, when it detects a failed session check, calls the AuthJs signOut method and redirects to the homepage. I created a separate session check so that if I manually delete the session entry for a user from the database, I can immediately invalidate their session. This works perfectly - the session token is deleted from the cookies, and if I try to navigate to a protected page, the system prevents access. However, I have the following problem, which I haven't been able to find a solution for yet (I'll note that I'm a beginner React/NextJs developer): In the header of my layout, there's a user "info" display that shows a SignIn button when not logged in, and the user's name and profile picture when logged in. Now, after forced sign-out (middleware signOut and redirect), this component doesn't refresh. It only shows the correct state when I reload the page. I haven't found a solution for how to re-render this part after the redirect.
Thanks in advance for the tips.
I've started working on a starter project in NextJs, using AuthJs as the authentication library. Everything is working well, and I've implemented database-level session checking in the middleware. I'm accessing the database with Drizzle ORM. The middleware, when it detects a failed session check, calls the AuthJs signOut method and redirects to the homepage. I created a separate session check so that if I manually delete the session entry for a user from the database, I can immediately invalidate their session. This works perfectly - the session token is deleted from the cookies, and if I try to navigate to a protected page, the system prevents access. However, I have the following problem, which I haven't been able to find a solution for yet (I'll note that I'm a beginner React/NextJs developer): In the header of my layout, there's a user "info" display that shows a SignIn button when not logged in, and the user's name and profile picture when logged in. Now, after forced sign-out (middleware signOut and redirect), this component doesn't refresh. It only shows the correct state when I reload the page. I haven't found a solution for how to re-render this part after the redirect.
Thanks in advance for the tips.
1 Reply
Yellow-faced GrassquitOP
Here is my repo: https://github.com/szig83/nextjs-starter