1
This commit is contained in:
@@ -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));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user