From 11d94918d46dc7bdbe3eea97eac48acee87a5fc0 Mon Sep 17 00:00:00 2001 From: Mark Terrel Date: Thu, 23 Dec 2021 09:17:47 -0700 Subject: [PATCH] fix(authentication-oauth): OAuth redirect lost sometimes due to session store race (#2514) --- packages/authentication-oauth/src/express.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/packages/authentication-oauth/src/express.ts b/packages/authentication-oauth/src/express.ts index 6401353f92..925cbab470 100644 --- a/packages/authentication-oauth/src/express.ts +++ b/packages/authentication-oauth/src/express.ts @@ -57,7 +57,19 @@ export default (options: OauthSetupSettings) => { req.session.redirect = redirect as string; req.session.query = query; - res.redirect(`${path}/connect/${name}?${qs.stringify(query as any)}`); + const sendRedirect = () => res.redirect(`${path}/connect/${name}?${qs.stringify(query as any)}`); + + if (typeof req.session.save === 'function') { + req.session.save((err: any) => { + if (err) { + res.status(500).send(`Error storing session: ${err}`); + } else { + sendRedirect(); + } + }); + } else { + sendRedirect(); + } }); authApp.get('/:name/callback', (req: any, res: any) => {