feat: citizenship applications
This commit is contained in:
+5
-3
@@ -2,7 +2,9 @@ import { SignJWT, jwtVerify } from "jose";
|
||||
import { cookies } from "next/headers";
|
||||
import { cookieConfig } from "@/lib/cookieConfig";
|
||||
|
||||
const secret = new TextEncoder().encode(process.env.JWT_SECRET!);
|
||||
function getSecret() {
|
||||
return new TextEncoder().encode(process.env.JWT_SECRET!);
|
||||
}
|
||||
|
||||
async function signJwt(userId: string) {
|
||||
return await new SignJWT({})
|
||||
@@ -10,7 +12,7 @@ async function signJwt(userId: string) {
|
||||
.setSubject(userId)
|
||||
.setIssuedAt()
|
||||
.setExpirationTime(`${process.env.SESSION_MAX_AGE}s`)
|
||||
.sign(secret);
|
||||
.sign(getSecret());
|
||||
}
|
||||
|
||||
export async function createSession(userId: string) {
|
||||
@@ -29,7 +31,7 @@ export async function getSessionUserId(): Promise<string | null> {
|
||||
if (!token) return null;
|
||||
|
||||
try {
|
||||
const { payload } = await jwtVerify(token, secret);
|
||||
const { payload } = await jwtVerify(token, getSecret());
|
||||
return payload.sub ?? null;
|
||||
} catch {
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user