Add back vc auth temporarily to unblock things

This commit is contained in:
Jared Palmer 2023-05-19 14:13:38 -04:00
parent 07c2e7d36a
commit 177b2cc210
20 changed files with 350 additions and 40 deletions

23
lib/session/server.ts Normal file
View file

@ -0,0 +1,23 @@
import { type NextApiRequest } from 'next';
import { type NextRequest } from 'next/server';
import { userSessionCookieName } from './constants';
import { decryptJWECookie } from '../cookies/decrypt-jwe';
import { type Session } from './types';
export async function getSessionFromCookie(cookieValue?: string) {
if (!cookieValue) return;
const session = await decryptJWECookie<Session>(cookieValue);
return session;
}
export async function getSessionFromReq(
req: NextApiRequest | NextRequest
): Promise<Session | undefined> {
const cookieValue =
'get' in req.cookies && typeof req.cookies.get === 'function'
? req.cookies.get(userSessionCookieName)?.value
: (req.cookies as Record<string, string>)[userSessionCookieName];
return getSessionFromCookie(cookieValue);
}