Add back vc auth temporarily to unblock things
This commit is contained in:
parent
07c2e7d36a
commit
177b2cc210
20 changed files with 350 additions and 40 deletions
23
lib/session/server.ts
Normal file
23
lib/session/server.ts
Normal 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);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue