init: me-web 个人简历前端

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
Superuser
2026-05-18 20:10:54 +08:00
commit ff98547dbb
116 changed files with 9460 additions and 0 deletions
+36
View File
@@ -0,0 +1,36 @@
import * as jose from "jose";
import { env } from "./env";
const JWT_ALG = "HS256";
export interface SessionPayload {
userId: number;
}
export async function signSessionToken(
payload: SessionPayload,
): Promise<string> {
const secret = new TextEncoder().encode(env.jwtSecret);
return new jose.SignJWT(payload)
.setProtectedHeader({ alg: JWT_ALG })
.setIssuedAt()
.setExpirationTime("1 year")
.sign(secret);
}
export async function verifySessionToken(
token: string,
): Promise<SessionPayload | null> {
if (!token) return null;
try {
const secret = new TextEncoder().encode(env.jwtSecret);
const { payload } = await jose.jwtVerify(token, secret, {
algorithms: [JWT_ALG],
});
const userId = payload.userId as number;
if (!userId) return null;
return { userId };
} catch {
return null;
}
}