+2
-2
netlify/functions/core/middleware/auth.middleware.ts
+2
-2
netlify/functions/core/middleware/auth.middleware.ts
···
15
const cookies = event.headers.cookie
16
? cookie.parse(event.headers.cookie)
17
: {};
18
-
const sessionId = cookies.atlast_session;
19
20
if (!sessionId) {
21
throw new AuthenticationError(ERROR_MESSAGES.NO_SESSION_COOKIE);
···
42
const cookies = event.headers.cookie
43
? cookie.parse(event.headers.cookie)
44
: {};
45
-
return cookies.atlast_session || null;
46
}
···
15
const cookies = event.headers.cookie
16
? cookie.parse(event.headers.cookie)
17
: {};
18
+
const sessionId = cookies.atlast_session || cookies.atlast_session_dev;
19
20
if (!sessionId) {
21
throw new AuthenticationError(ERROR_MESSAGES.NO_SESSION_COOKIE);
···
42
const cookies = event.headers.cookie
43
? cookie.parse(event.headers.cookie)
44
: {};
45
+
return cookies.atlast_session || cookies.atlast_session_dev || null;
46
}
+3
-2
netlify/functions/logout.ts
+3
-2
netlify/functions/logout.ts
···
24
console.log("[logout] Successfully deleted session:", sessionId);
25
}
26
27
-
const config = getOAuthConfig();
28
const isDev = config.clientType === "loopback";
29
30
const cookieFlags = isDev
31
? `HttpOnly; SameSite=Lax; Max-Age=0; Path=/`
···
35
statusCode: 200,
36
headers: {
37
"Content-Type": "application/json",
38
-
"Set-Cookie": `atlast_session=; ${cookieFlags}`,
39
},
40
body: JSON.stringify({ success: true }),
41
};
···
24
console.log("[logout] Successfully deleted session:", sessionId);
25
}
26
27
+
const config = getOAuthConfig(event);
28
const isDev = config.clientType === "loopback";
29
+
const cookieName = isDev ? "atlast_session_dev" : "atlast_session";
30
31
const cookieFlags = isDev
32
? `HttpOnly; SameSite=Lax; Max-Age=0; Path=/`
···
36
statusCode: 200,
37
headers: {
38
"Content-Type": "application/json",
39
+
"Set-Cookie": `${cookieName}=; ${cookieFlags}`,
40
},
41
body: JSON.stringify({ success: true }),
42
};
+5
-3
netlify/functions/oauth-callback.ts
+5
-3
netlify/functions/oauth-callback.ts
···
43
44
console.log("[oauth-callback] Created user session:", sessionId);
45
46
const cookieFlags = isDev
47
? `HttpOnly; SameSite=Lax; Max-Age=${CONFIG.COOKIE_MAX_AGE}; Path=/`
48
: `HttpOnly; SameSite=Lax; Max-Age=${CONFIG.COOKIE_MAX_AGE}; Path=/; Secure`;
49
50
-
return redirectResponse(`${currentUrl}/?session=${sessionId}`, [
51
-
`atlast_session=${sessionId}; ${cookieFlags}`,
52
-
]);
53
};
54
55
export const handler = withErrorHandling(oauthCallbackHandler);
···
43
44
console.log("[oauth-callback] Created user session:", sessionId);
45
46
+
const cookieName = isDev ? "atlast_session_dev" : "atlast_session";
47
const cookieFlags = isDev
48
? `HttpOnly; SameSite=Lax; Max-Age=${CONFIG.COOKIE_MAX_AGE}; Path=/`
49
: `HttpOnly; SameSite=Lax; Max-Age=${CONFIG.COOKIE_MAX_AGE}; Path=/; Secure`;
50
51
+
return redirectResponse(
52
+
`${currentUrl}/?session=${sessionId}`,
53
+
`${cookieName}=${sessionId}; ${cookieFlags}`,
54
+
);
55
};
56
57
export const handler = withErrorHandling(oauthCallbackHandler);
+5
-5
netlify/functions/utils/response.utils.ts
+5
-5
netlify/functions/utils/response.utils.ts
···
45
46
export function redirectResponse(
47
location: string,
48
-
setCookies?: string[],
49
): HandlerResponse {
50
-
const headers: Record<string, string | string[]> = {
51
Location: location,
52
};
53
54
-
if (setCookies && setCookies.length > 0) {
55
-
headers["Set-Cookie"] = setCookies;
56
}
57
58
return {
59
statusCode: 302,
60
-
headers: headers as HandlerResponse["headers"],
61
body: "",
62
};
63
}
···
45
46
export function redirectResponse(
47
location: string,
48
+
setCookie?: string,
49
): HandlerResponse {
50
+
const headers: Record<string, string> = {
51
Location: location,
52
};
53
54
+
if (setCookie) {
55
+
headers["Set-Cookie"] = setCookie;
56
}
57
58
return {
59
statusCode: 302,
60
+
headers,
61
body: "",
62
};
63
}