'Next-Auth - MongoDB storing Sessions
I am trying to intergrate Next-Auth and at the moment I have the signup and login code working.
However now I need to create the session collection which I have done but because on login the following does not update or insert into session collection I am currently not able to check the userID and if they have a valid session.
Only 1 session per user should be allowed - and if the session does not match the userID or it did match but was an old session it should require them to re-login and auto log them out of the other session.
In my code I have [...nextauth].js file I have the following.
callbacks: {
jwt: async ({ token, user }) => {
user && (token.user = user)
return token
},
session: async ({ session, token }) => {
console.log(JSON.stringify(session) +" / "+ JSON.stringify(token));
session.user = token.user
return session
}
},
I am wondering is it inside session: async that I put the MongoDB code to update the session collection? or is it somewhere else?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
