Spaces:
Sleeping
Sleeping
Download src/modules/auth/application/services/TokenService.ts from fouadkhalid123/asd: direct link, hf CLI and curl.
- Browser
- Download file 875 Bytes
-
https://huggingface.co/spaces/fouadkhalid123/asd/resolve/main/src/modules/auth/application/services/TokenService.ts
- Command line
-
hf download hf://spaces/fouadkhalid123/asd/src/modules/auth/application/services/TokenService.ts
-
curl -L -o TokenService.ts https://huggingface.co/spaces/fouadkhalid123/asd/resolve/main/src/modules/auth/application/services/TokenService.ts
875 Bytes
| import jwt from "jsonwebtoken"; | |
| import crypto from "crypto"; | |
| import { JtiStore } from "../../../../libs/shared/infrastructure/memory/JtiStore"; | |
| import { env } from "../../../../config/env"; | |
| export interface TokenPayload { | |
| sub: string; | |
| organizationId: string; | |
| storeId: string; | |
| } | |
| export class TokenService { | |
| private readonly secret = env.SESSION_SECRET; | |
| private readonly ttlSeconds = 60 * 60 * 24 * 7; // 7 days | |
| async generateToken(payload: TokenPayload): Promise<string> { | |
| const jti = crypto.randomUUID(); | |
| const expiresAt = Date.now() + this.ttlSeconds * 1000; | |
| const token = jwt.sign( | |
| { | |
| ...payload, | |
| jti | |
| }, | |
| this.secret, | |
| { expiresIn: this.ttlSeconds } | |
| ); | |
| JtiStore.set(jti, payload.sub, expiresAt); | |
| return token; | |
| } | |
| } | |