feat(auth): session closed after token expires
This commit is contained in:
@@ -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",
|
||||
},
|
||||
};
|
||||
|
||||
@@ -55,12 +55,11 @@ export const authOptions: AuthOptions = {
|
||||
image: token_payload.picture,
|
||||
name: token_payload.username,
|
||||
apiSession: {
|
||||
exp: token_payload.exp,
|
||||
accessToken: response_body.access_token,
|
||||
},
|
||||
};
|
||||
|
||||
console.log("__loged:", user);
|
||||
|
||||
return user;
|
||||
},
|
||||
}),
|
||||
|
||||
1
front/src/modules/auth/types/next-auth.d.ts
vendored
1
front/src/modules/auth/types/next-auth.d.ts
vendored
@@ -4,6 +4,7 @@ import { JWT, DefaultJWT } from "next-auth/jwt";
|
||||
declare module "next-auth" {
|
||||
type Role = "user" | "manager" | "admin";
|
||||
interface ApiSession {
|
||||
exp?: number;
|
||||
accessToken: string;
|
||||
refreshToken?: string;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user