fix profile

This commit is contained in:
not-nullptr 2024-03-10 21:35:50 +00:00
parent 5bfaf053a0
commit a5b383aa5d
2 changed files with 17 additions and 3 deletions

View file

@ -1,4 +1,7 @@
import type { IJwtData } from "$types/auth";
import type { Role } from "$types/db";
import { PUBLIC_KEY } from "../secrets";
import jwt from "jsonwebtoken";
export function json<T>(body: T): Response {
return new Response(JSON.stringify(body), {
@ -15,3 +18,12 @@ export function serializeRoles(roles: Role[]): string {
export function deserializeRoles(roles: string): Role[] {
return roles.split("|") as Role[];
}
export async function getJwtData(token: string): Promise<IJwtData> {
return new Promise((resolve, reject) => {
jwt.verify(token, PUBLIC_KEY, { algorithms: ["RS256"] }, (err, data) => {
if (err) reject(err);
else resolve(data as IJwtData);
});
});
}