forked from Mike/freno-dev
cairn work
This commit is contained in:
23
src/server/cairn-auth.ts
Normal file
23
src/server/cairn-auth.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import { jwtVerify } from "jose";
|
||||
import { env } from "~/env/server";
|
||||
|
||||
export type CairnAuthPayload = {
|
||||
sub: string;
|
||||
exp?: number;
|
||||
iat?: number;
|
||||
};
|
||||
|
||||
export async function verifyCairnToken(
|
||||
token: string
|
||||
): Promise<CairnAuthPayload> {
|
||||
const secret = new TextEncoder().encode(env.CAIRN_JWT_SECRET);
|
||||
const { payload } = await jwtVerify(token, secret, {
|
||||
algorithms: ["HS256"]
|
||||
});
|
||||
|
||||
return {
|
||||
sub: payload.sub as string,
|
||||
exp: payload.exp as number | undefined,
|
||||
iat: payload.iat as number | undefined
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user