How would I programmatically sign out a user in Next-Auth on the server side?
Inside /api/auth/[...nextauth].js there is a jwt function:
const callbacks = {
async jwt ({ token, user }) {
// How to sign out a user?
signOut(); <--- can't use this on the server side
}
}
Unfortunately, the signOut() function is only for the client side. It produces an error if used here.
I have read the very bare-bones Next Auth REST API page and I can't get a POST call to "/api/auth/signout" to work. If that is the correct method can someone show me some working code? Does it need any kind of authorization token?
https://next-auth.js.org/getting-started/rest-api
Thanks!
As of the time of this answer, there's seems to be no support for server-side logout on next-auth.
Source: nextauth Github issue 5334
There are workarounds like clearing the cookie or redirecting the user to an auto logout page, but nothing official or straight forward.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With