Spaces:
Sleeping
Sleeping
Download src/utils/jwt.ts from Anoderb/Tokiva-backend-Node: direct link, hf CLI and curl.
- Browser
- Download file 718 Bytes
-
https://huggingface.co/spaces/Anoderb/Tokiva-backend-Node/resolve/main/src/utils/jwt.ts
- Command line
-
hf download hf://spaces/Anoderb/Tokiva-backend-Node/src/utils/jwt.ts
-
curl -L -o jwt.ts https://huggingface.co/spaces/Anoderb/Tokiva-backend-Node/resolve/main/src/utils/jwt.ts
718 Bytes
| import jwt from 'jsonwebtoken'; | |
| import dotenv from 'dotenv'; | |
| dotenv.config(); | |
| const JWT_SECRET = process.env.JWT_SECRET_KEY || 'defaultsecret'; | |
| export const createAccessToken = (data: object): string => { | |
| return jwt.sign( | |
| { ...data, type: 'access' }, | |
| JWT_SECRET, | |
| { expiresIn: '24h' } // Matching python JWT_ACCESS_TOKEN_EXPIRE_MINUTES = 1440 mins (24h) | |
| ); | |
| }; | |
| export const createRefreshToken = (data: object): string => { | |
| return jwt.sign( | |
| { ...data, type: 'refresh' }, | |
| JWT_SECRET, | |
| { expiresIn: '30d' } // Matching python 30 days | |
| ); | |
| }; | |
| export const verifyToken = (token: string): any => { | |
| try { | |
| return jwt.verify(token, JWT_SECRET); | |
| } catch (error) { | |
| return null; | |
| } | |
| }; | |