From 589f9f1a360f323eb9895c1ec0f8ab4700795ea0 Mon Sep 17 00:00:00 2001 From: qowevisa Date: Fri, 8 Nov 2024 17:13:39 +0200 Subject: [PATCH] Apply changes to /api/auth/login route to change cookies --- src/routes/api/auth/login/+server.js | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/src/routes/api/auth/login/+server.js b/src/routes/api/auth/login/+server.js index f01bbdc..413fecb 100644 --- a/src/routes/api/auth/login/+server.js +++ b/src/routes/api/auth/login/+server.js @@ -16,21 +16,11 @@ export async function POST({ request, cookies }) { console.log("in POST3") try { console.log("in POST4") - const loginResponse = await login(username, password); // Call the backend login + const loginResponse = await login(username, password, cookies); console.log("loginResponse = ", loginResponse) - const session = loginResponse.headers.get("Set-Cookie"); - - // Set cookie securely on the server - cookies.set('session', loginResponse.token, { - httpOnly: true, // Prevents JavaScript access - secure: process.env.NODE_ENV === 'production', // Only send over HTTPS in production - sameSite: 'Strict', // Ensures the cookie is only sent in a first-party context - maxAge: 3600 // Expiry time in seconds (e.g., 1 hour) - }); - console.log("in POST5") - return json({ id: loginResponse.id, name: loginResponse.name }); // Return necessary data + return json({ id: loginResponse.id, name: loginResponse.name }); } catch (error) { return json({ error: error.message }, { status: 401 }); }