Files
tom goriunovandGitHub aa8bdb3fc7 Add "Secure" flag to all cookies (#3301)
* Add "Secure" flag to all cookies

Resolves #3296

* more fixes
2026-02-26 17:53:02 +01:00

24 lines
829 B
TypeScript

import type { NextRequest, NextResponse } from 'next/server';
import * as cookiesLib from 'lib/cookies';
const APP_PROFILE_HEADER = 'x-app-profile';
const APP_PROFILE_QUERY_PARAM = 'app-profile';
const PRIVATE_PROFILE_VALUE = 'private';
export default function appProfileMiddleware(req: NextRequest, res: NextResponse) {
const headerValue = req.headers.get(APP_PROFILE_HEADER);
// for testing purposes
const queryValue = req.nextUrl.searchParams.get(APP_PROFILE_QUERY_PARAM);
const profileValue = headerValue || queryValue;
if (profileValue === PRIVATE_PROFILE_VALUE) {
res.cookies.set(cookiesLib.NAMES.APP_PROFILE, PRIVATE_PROFILE_VALUE, cookiesLib.getDefaultAttributes());
} else {
res.cookies.delete({
name: cookiesLib.NAMES.APP_PROFILE,
...cookiesLib.getDefaultAttributes(),
});
}
}