Creating logout as next-auth?

Hey, so I was wondering how I could achieve something like next-auth logout/signout? I have a simple project that just stores a jwt token as a cookie. And I want it to be just like in next-auth, where you log out in one chrome tab, then it automatically logs out in any other open chrome tab. Could anyone explain to me how they achieve this?
9 Replies
erik.gh
erik.gh15mo ago
Why don't you just clear the cookie?
Børge
Børge15mo ago
Would that also logout on other chrome tabs instant?
erik.gh
erik.gh15mo ago
sure if it's the same chrome instance
Børge
Børge15mo ago
I don't really see how. In the video below, I used the swr auth example, because it was already set up. But shouldn't that then log me out on the other chrome tab instant? Here's the link for the example: https://codesandbox.io/s/swr-auth-vl653w?from-embed=&file=/pages/index.js:418-427
Børge
Børge15mo ago
erik.gh
erik.gh15mo ago
the page needs to reload
Børge
Børge15mo ago
I don't really know if you mean this. But I added window.location.reload(), and it still dosen't logout on the other browser.
Aleed.dev
Aleed.dev15mo ago
Ummm so I might not be right like have a wrapper along ur component that use useffect to fetch the cookies so that when ever the cookies get cleared it redirect the person back to login
erik.gh
erik.gh15mo ago
so you want it to be realtime?
Want results from more Discord servers?
Add your server