mirror of
https://git.suyu.dev/suyu/website.git
synced 2025-12-24 08:14:38 +01:00
fix profile
This commit is contained in:
parent
5bfaf053a0
commit
a5b383aa5d
2 changed files with 17 additions and 3 deletions
|
|
@ -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);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,10 @@
|
|||
import { json } from "$lib/server/util/index";
|
||||
import { useAuth } from "$lib/util/api/index.js";
|
||||
|
||||
export function GET({ request }) {
|
||||
console.log(request.headers.get("Authorization"));
|
||||
export async function GET({ request }) {
|
||||
const user = await useAuth(request.headers.get("authorization") || "");
|
||||
if (!user) return new Response(null, { status: 401 });
|
||||
return json({
|
||||
username: "nullptr",
|
||||
username: user.username,
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue