This commit is contained in:
2026-04-10 15:37:02 +08:00
parent 161cd32277
commit f19e482c8f
233 changed files with 43987 additions and 5127 deletions

View File

@@ -1,8 +1,24 @@
import crypto from 'node:crypto';
import { jwtVerify, SignJWT } from 'jose';
import type { AppConfig } from '../config.js';
import { unauthorized } from '../errors.js';
if (!globalThis.crypto?.subtle) {
Object.assign(globalThis, {
crypto: crypto.webcrypto,
});
}
if (typeof globalThis.structuredClone !== 'function') {
Object.assign(globalThis, {
structuredClone<T>(value: T) {
return JSON.parse(JSON.stringify(value)) as T;
},
});
}
export type AccessTokenClaims = {
userId: string;
tokenVersion: number;
@@ -21,6 +37,7 @@ export async function signAccessToken(
.setSubject(claims.userId)
.setIssuer(config.jwtIssuer)
.setIssuedAt()
.setExpirationTime(config.jwtExpiresIn)
.sign(getSecret(config));
}