Refresh the page after authClient.signOut()
I have something like
- I have an index, a login and a protected page
- On the protected page, I display the session and have a sign out button
- When I click on sign out, I do get signed out[I see that the better-auth session is removed from the cookies] and I am then redirected to the home page
- But even after that, if I navigate to the, say, protected page, I can still see the session that I had displayed, the sign out button, etc.
- However, when I refresh the page, then things work normally. I am prompted to login again.
I'm new to Nuxt.
I'm thinking it has something to do with caching or some of the checks not being performed on the client.
Does anyone have an idea what I might be missing?
Setup: Nuxt | Better-Auth | Drizzle ORM | PostgreSQL | Google Provider
Thank you.
3 Replies
Extra Info:
I have a global middleware like:
The login is being done like:
UPDATE:
It turns out that if I do:
It refreshes the page on sign out, and then that state isn't kept and I can't see the previous session data. However, I'm 100% sure this isn't how it should be done.
I have the feeling it has to do with some SSR stuff
Like, checking if we are on the client, then do things differently, Idk.
You should be able to do the following:
If you don't wait for the sign-out to finish you can encounter some bugs. But you may also want to handle the failure events.
navigateTo
should preserve your state as it will use the Nuxt router.HUH! That actually solved it. THANK YOU, @Winter .