mirror of
https://github.com/umami-software/umami.git
synced 2026-02-11 08:07:12 +01:00
Imported libraries, removed next-basics.
This commit is contained in:
parent
31266cb1ac
commit
113022ed17
44 changed files with 361 additions and 180 deletions
36
src/lib/jwt.ts
Normal file
36
src/lib/jwt.ts
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
import jwt from 'jsonwebtoken';
|
||||
import { decrypt, encrypt } from 'lib/crypto';
|
||||
|
||||
export function createToken(payload: any, secret: any, options?: any) {
|
||||
return jwt.sign(payload, secret, options);
|
||||
}
|
||||
|
||||
export function parseToken(token: string, secret: any) {
|
||||
try {
|
||||
return jwt.verify(token, secret);
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
export function createSecureToken(payload: any, secret: any, options?: any) {
|
||||
return encrypt(createToken(payload, secret, options), secret);
|
||||
}
|
||||
|
||||
export function parseSecureToken(token: string, secret: any) {
|
||||
try {
|
||||
return jwt.verify(decrypt(token, secret), secret);
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
export async function parseAuthToken(req: Request, secret: string) {
|
||||
try {
|
||||
const token = req.headers.get('authorization')?.split(' ')?.[1];
|
||||
|
||||
return parseSecureToken(token as string, secret);
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue