fix sameSite

This commit is contained in:
2026-04-21 21:05:12 +01:00
parent 51a7e85858
commit c9e96d489d
3 changed files with 11 additions and 9 deletions
+2 -2
View File
@@ -35,7 +35,7 @@ export async function GET(req: Request) {
response.cookies.set("access_token", data.access_token, { response.cookies.set("access_token", data.access_token, {
httpOnly: true, httpOnly: true,
secure: isHttps, secure: isHttps,
sameSite: "none", sameSite: isHttps ? "none" : "lax",
path: "/", path: "/",
...(env.COOKIE_DOMAIN ? { domain: env.COOKIE_DOMAIN } : {}), ...(env.COOKIE_DOMAIN ? { domain: env.COOKIE_DOMAIN } : {}),
maxAge: data.expires_in, maxAge: data.expires_in,
@@ -44,7 +44,7 @@ export async function GET(req: Request) {
response.cookies.set("refresh_token", data.refresh_token, { response.cookies.set("refresh_token", data.refresh_token, {
httpOnly: true, httpOnly: true,
secure: isHttps, secure: isHttps,
sameSite: "none", sameSite: isHttps ? "none" : "lax",
path: "/", path: "/",
...(env.COOKIE_DOMAIN ? { domain: env.COOKIE_DOMAIN } : {}), ...(env.COOKIE_DOMAIN ? { domain: env.COOKIE_DOMAIN } : {}),
maxAge: data.expires_in, maxAge: data.expires_in,
+3 -1
View File
@@ -3,13 +3,15 @@ import { NextResponse } from "next/server";
export async function POST(req: Request) { export async function POST(req: Request) {
const { token } = await req.json(); const { token } = await req.json();
const isHttps = new URL(req.url).protocol === "https:";
const res = NextResponse.json({ ok: true }); const res = NextResponse.json({ ok: true });
res.cookies.set("auth_token", token, { res.cookies.set("auth_token", token, {
httpOnly: true, httpOnly: true,
secure: true, secure: true,
sameSite: "none", sameSite: isHttps ? "none" : "lax",
...(env.COOKIE_DOMAIN ? { domain: env.COOKIE_DOMAIN } : {}), ...(env.COOKIE_DOMAIN ? { domain: env.COOKIE_DOMAIN } : {}),
path: "/", path: "/",
}); });
+6 -6
View File
@@ -1,10 +1,10 @@
// /** // // /**
// * TOKEN REFRESHER // // * TOKEN REFRESHER
// * Logic: Silent background token rotation. // // * Logic: Silent background token rotation.
// * Role: Communicates with Keycloak to exchange a Refresh Token for a new Access Token. // // * Role: Communicates with Keycloak to exchange a Refresh Token for a new Access Token.
// */ // // */
// import { keycloakConfig } from './keycloak-config'; // // import { keycloakConfig } from './keycloak-config';
// export const refreshAccessToken = async (token: any) => { // export const refreshAccessToken = async (token: any) => {
// try { // try {