initial commit

This commit is contained in:
Ivan Rezchikov
2026-06-18 22:37:03 +03:00
parent d5d42a2141
commit 6c89f21039
30 changed files with 1506 additions and 95 deletions
+22
View File
@@ -0,0 +1,22 @@
import { SignJWT, jwtVerify } from "jose";
const secret = new TextEncoder().encode(process.env.JWT_SECRET!);
export async function signJwt(userId: string) {
return await new SignJWT({})
.setProtectedHeader({ alg: "HS256" })
.setSubject(userId)
.setIssuedAt()
.setExpirationTime(`${process.env.SESSION_MAX_AGE}s`)
.sign(secret);
}
export async function verifyJwt(token: string) {
try {
const { payload } = await jwtVerify(token, secret);
return payload;
} catch {
return null;
}
}