Skip to content
Advertisement

Next-Auth Signout within jwt callback

If a user is signed into the app between app upgrades, then I want to sign out the user the next time they visit.

I am pulling the version in from the package.json and storing it in the jwt/session to have for comparison of which version the user authenticated from and what version is now running.

JavaScript

This works, but it is throwing an error

JavaScript

I know the error is throwing because I am calling the signOut function on the server side when it is meant to be a browser side function hence the error for window is not defined.

How else can I call the signOut function without it trying to use the browser side call including the reference to window?

Advertisement

Answer

You can’t use signOut on sever side from what I gathered, but here is a trick I used in my case. Instead trying signOut from the server side return an error code.

JavaScript

Create a wrapper around the secured routes. you can do this in a common layout too.

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement