From 01d6043739134594054a506c058b44552ddc6949 Mon Sep 17 00:00:00 2001 From: Harhio Date: Tue, 17 Dec 2024 14:12:45 +0200 Subject: [PATCH] DT-6631 fix hsl login --- src/setupProxy.js | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/src/setupProxy.js b/src/setupProxy.js index 75c5e9e8..1e154846 100644 --- a/src/setupProxy.js +++ b/src/setupProxy.js @@ -1,12 +1,29 @@ /* eslint-disable */ const { createProxyMiddleware } = require('http-proxy-middleware'); +const setLocalhostCookies = proxyRes => { + if ( + process.env.NODE_ENV === 'development' && + proxyRes.headers.location === 'http://localhost:3000/' && + proxyRes.headers['set-cookie'] !== undefined + ) { + const cookies = proxyRes.headers['set-cookie'].map( + // get browser to set cookie for testing + cookie => cookie.replace('SameSite=None', 'SameSite=Strict; Secure'), + ); + proxyRes.headers["set-cookie"] = cookies; + } +}; + module.exports = function (app) { app.use( '/oid_callback', createProxyMiddleware({ target: 'http://localhost:3001', changeOrigin: true, + onProxyRes: function (proxyRes) { + setLocalhostCookies(proxyRes); + }, }), ); app.use( @@ -15,15 +32,7 @@ module.exports = function (app) { target: 'http://localhost:3001', changeOrigin: true, onProxyRes: function (proxyRes) { - if (process.env.NODE_ENV === "development" && - proxyRes.headers.location === "http://localhost:3000/" && - proxyRes.headers["set-cookie"] !== undefined) { - const cookies = proxyRes.headers["set-cookie"].map( - // get browser to set cookie for testing - (cookie) => cookie.replace("SameSite=None", "SameSite=Strict; Secure") - ); - proxyRes.headers["set-cookie"] = cookies; - } + setLocalhostCookies(proxyRes); }, }), );