mirror of
https://github.com/nfonteyne/octane-website.git
synced 2026-09-03 23:24:48 +02:00
fix: more robust cookie session
This commit is contained in:
parent
d62596abcc
commit
aca521b54f
2 changed files with 17 additions and 1 deletions
|
|
@ -8,6 +8,10 @@ const apiRouter = require('./routes');
|
|||
function createApp() {
|
||||
const app = express();
|
||||
|
||||
// Behind Traefik: without this, req.protocol/req.secure ignore
|
||||
// X-Forwarded-Proto and always report the plain-HTTP hop to the container.
|
||||
app.set('trust proxy', 1);
|
||||
|
||||
app.get('/health', (req, res) => res.status(200).json({ status: 'ok' }));
|
||||
|
||||
app.use(express.json());
|
||||
|
|
|
|||
|
|
@ -83,7 +83,13 @@ router.get(
|
|||
code_challenge_method: 'S256',
|
||||
});
|
||||
|
||||
// Force the session write to complete (and surface any store error)
|
||||
// before sending the redirect, instead of relying on express-session's
|
||||
// implicit save-on-response-end behavior.
|
||||
req.session.save((err) => {
|
||||
if (err) throw err;
|
||||
res.redirect(authUrl.href);
|
||||
});
|
||||
})
|
||||
);
|
||||
|
||||
|
|
@ -97,6 +103,12 @@ router.get(
|
|||
const oidcConfig = getOidcConfig();
|
||||
const pending = req.session.oidc;
|
||||
if (!pending) {
|
||||
console.warn(
|
||||
'[auth] /auth/callback reached with no pending OIDC state.',
|
||||
'sessionID:', req.sessionID,
|
||||
'cookie header present:', Boolean(req.headers.cookie),
|
||||
'session keys:', Object.keys(req.session || {}),
|
||||
);
|
||||
return res.status(400).send('Session de connexion expirée, réessayez.');
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue