Skip to content

Commit

Permalink
fix possible undefined setcookie header
Browse files Browse the repository at this point in the history
  • Loading branch information
thostetler committed May 9, 2024
1 parent 8ce859e commit 4492c40
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/middlewares/initSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { edgeLogger } from '@/logger';
// eslint-disable-next-line @next/next/no-server-import-in-page
import { NextRequest, NextResponse } from 'next/server';
import { botCheck } from '@/middlewares/botCheck';
import setCookie from 'set-cookie-parser';

/**
* Checks if the user data is valid
Expand Down Expand Up @@ -142,7 +143,7 @@ export const initSession = async (req: NextRequest, res: NextResponse) => {
session.token = token;
session.isAuthenticated = isAuthenticated(token);
log.debug({ msg: 'headers', headers: headers.entries() });
const sessionCookieValue = headers.get('set-cookie').split('=')[1] ?? '';
const sessionCookieValue = setCookie.parse(headers.get('set-cookie') ?? '')[0].value;
res.cookies.set(process.env.ADS_SESSION_COOKIE_NAME, sessionCookieValue);
session.apiCookieHash = await hash(res.cookies.get(process.env.ADS_SESSION_COOKIE_NAME)?.value);
await session.save();
Expand Down

0 comments on commit 4492c40

Please sign in to comment.