Reputation: 206
I'm using the credentials provider of Next-Auth, where the sign in would set the user into the token, then into the session. The set cookies is also applied.
In order to signOut, I overrode the default signOut Method
[...nextauth].ts
events: {
async signOut({ token, session }) {
// Delete auth cookie on signout so it doesn't persist past log out
res.setHeader("Set-Cookie", "");
}
},
However, now my session doesn't refresh or destroy itself. So the cilentside still thinks I'm logged in even after calling the sign out method.
How can I force refresh the token/session in the serverside? Would it just be setting token/session = {}
in signOut? Is there some default method that can do that?
Upvotes: 1
Views: 10639
Reputation: 6826
Can you use the signIn
callback instead?
export const authOptions: NextAuthOptions = {
callbacks: {
signIn({ user }) {
return user?.email === '[email protected]';
},
},
};
Here's their documentation if you want to read further. next-auth
You can also return a string for the signIn
callback, which will act as a redirect.
Upvotes: 0
Reputation: 206
It was like my initial thoughts, just set token/session = {}, then that would delete the session accordingly.
async signOut({ token, session }) {
// Delete auth cookie on signout so it doesn't persist past log out
res.setHeader("Set-Cookie", "");
// Set token/session to {}, that would update the cilentside token/session as well
token = {};
session = {};
}
Upvotes: 1