This commit is contained in:
2026-01-21 11:29:07 -05:00
parent 6b86d175e8
commit 1d8ec7a375
3 changed files with 552 additions and 47 deletions

View File

@@ -1,6 +1,9 @@
import { jwtVerify } from "jose";
import { SignJWT, jwtVerify } from "jose";
import { env } from "~/env/server";
const CAIRN_JWT_EXPIRY = "30d";
export type CairnAuthPayload = {
sub: string;
exp?: number;
@@ -15,9 +18,23 @@ export async function verifyCairnToken(
algorithms: ["HS256"]
});
if (!payload.sub) {
throw new Error("Missing subject in Cairn JWT");
}
return {
sub: payload.sub as string,
exp: payload.exp as number | undefined,
iat: payload.iat as number | undefined
};
}
export async function signCairnToken(userId: string): Promise<string> {
const secret = new TextEncoder().encode(env.CAIRN_JWT_SECRET);
return new SignJWT({})
.setProtectedHeader({ alg: "HS256" })
.setSubject(userId)
.setIssuedAt()
.setExpirationTime(CAIRN_JWT_EXPIRY)
.sign(secret);
}