-
IssueThe problem is browsers keep login session until user press 'logout' button. (when user close the browser and reopen browser, it still remember user's session) So i'd like to add +) Can't be able to access backend code. I have to figure out this on Front (Next.js) QuestionI'd like to know the best way for automatically log out of user's browser after a long period of inactivity or after specific time when user dosen't clicked Any help ? 🙏 (Simmilar issue #776) Some ideas
ScreenshotCode[...nextauth].js /* eslint-disable */
import NextAuth from 'next-auth';
import CredentialsProvider from 'next-auth/providers/credentials';
import { getAccessToken, getUserInformationByToken } from '@/pages/api/index';
export default NextAuth({
providers: [
CredentialsProvider({
name: 'Credentials',
async authorize(credentials, req) {
// get JWT token
const accessToken = await getAccessToken(credentials).then(function (
response
) {
return response;
});
console.log('\n token : ', accessToken);
// get user info from token
const userInfo = await getUserInformationByToken(accessToken).then(
function (response) {
return response;
}
);
// return user information
if (userInfo) {
userInfo['accessToken'] = accessToken;
return userInfo;
} else {
throw new Error('Incorrect Credentials');
// return null;
}
},
}),
],
callbacks: {
jwt: async ({ token, user }) => {
user && (token.user = user);
return token;
},
session: async ({ session, token }) => {
// maxAge: 5;
session.user = token.user;
return session;
},
},
pages: {
signIn: '/auth/login',
},
secret: process.env.SECRET,
}); |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
Usually, this is outside the scope of something like this tool as it requires adding multiple event listeners... What I would recommend doing is building a wrapper around your app, like when you do theming or user contexts which manages this for you The below is untested, but could help you getting in the right direction:
|
Beta Was this translation helpful? Give feedback.
Usually, this is outside the scope of something like this tool as it requires adding multiple event listeners...
What I would recommend doing is building a wrapper around your app, like when you do theming or user contexts which manages this for you
The below is untested, but could help you getting in the right direction: