Skip to content

Commit

Permalink
chore: custom iat in JWT
Browse files Browse the repository at this point in the history
  • Loading branch information
ful1e5 committed Nov 21, 2023
1 parent b90ddf7 commit 4f56890
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/utils/auth/token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import { JWTToken } from 'bibata/misc';
const SECRET_KEY = process.env.NEXT_PUBLIC_JWT_SECRET;
export const genAccessToken = (user?: User) => {
const token_id = v4();
const iat = Math.floor(Date.now() / 1000);

let payload = { token_id, role: 'ANONYMOUS' };
if (user) payload = { ...user, token_id };
let payload = { iat, token_id, role: 'ANONYMOUS' };
if (user) payload = { iat, token_id, ...user };

const token = jwt.sign(payload, process.env.NEXT_PUBLIC_JWT_SECRET, {
algorithm: 'HS256',
expiresIn: 360
algorithm: 'HS256'
});

return {
Expand Down

0 comments on commit 4f56890

Please sign in to comment.