cookie handling
CI / ci (push) Canceled after 0s

This commit is contained in:
Stefan Lazic committed 2026-09-04 22:53:35 +01:00
1 parent 8fddde6d4b
commit ac9791c8ef
2 files changed
+9 -2

No files matched your search

@@ -35,6 +35,7 @@ describe("Manager session cookie", () => {
expect.any(String), expect.any(String),
expect.objectContaining({ secure: false, path: "/" }), expect.objectContaining({ secure: false, path: "/" }),
); );
expect(cookieSet).toHaveBeenCalledWith("nextchair_manager_session", "", { path: "/manager", maxAge: 0 });
}); });
it("marks the cookie Secure for an HTTPS deployment", async () => { it("marks the cookie Secure for an HTTPS deployment", async () => {
+8 -2
View File
@@ -25,7 +25,11 @@ export function authenticateManager(email: string, password: string) {
export async function createManagerSession() { export async function createManagerSession() {
const config = getManagerConfig(); const config = getManagerConfig();
const value = `${config.adminEmail.trim().toLowerCase()}.${Date.now()}`; const value = `${config.adminEmail.trim().toLowerCase()}.${Date.now()}`;
(await cookies()).set(COOKIE_NAME, `${value}.${signature(value, config.authSecret)}`, { const store = await cookies();
// Remove sessions issued by older builds with Path=/manager. Browsers can
// retain both cookies, and the stale one may be selected first on /manager.
store.set(COOKIE_NAME, "", { path: "/manager", maxAge: 0 });
store.set(COOKIE_NAME, `${value}.${signature(value, config.authSecret)}`, {
httpOnly: true, httpOnly: true,
sameSite: "strict", sameSite: "strict",
secure: isSecureDeployment(), secure: isSecureDeployment(),
@@ -37,7 +41,9 @@ export async function createManagerSession() {
} }
export async function clearManagerSession() { export async function clearManagerSession() {
(await cookies()).delete(COOKIE_NAME); const store = await cookies();
store.delete(COOKIE_NAME);
store.set(COOKIE_NAME, "", { path: "/manager", maxAge: 0 });
} }
export async function isManagerAuthenticated() { export async function isManagerAuthenticated() {