feat(auth): session closed after token expires

This commit is contained in:
2024-09-03 22:38:25 +02:00
parent 92d5035e4e
commit 6b1bde7a5d
3 changed files with 25 additions and 3 deletions

View File

@@ -5,7 +5,9 @@ export default withAuth({
pages: authOptions.pages,
callbacks: {
authorized({ req, token }) {
if (token) return true;
if (token && token.apiSession.exp * 1000 > Date.now()) {
return true;
}
const pathname = req.nextUrl.pathname;
return (
pathname.startsWith("/_next/") ||
@@ -15,3 +17,23 @@ export default withAuth({
},
},
});
const value = {
token: {
name: "dqnid",
picture: "https://picsum.photos/200/300",
sub: "dqnid",
user: {
id: "dqnid",
roles: ["user", "manager", "admin"],
image: "https://picsum.photos/200/300",
name: "dqnid",
},
apiSession: {
exp: 1725398177,
},
iat: 1725394577,
exp: 1727986577,
jti: "3203d3c7-dc27-4599-b37e-16737b3a6674",
},
};