From 2805cb7cb68cae0f25bd43f166e4a6b8501d41eb Mon Sep 17 00:00:00 2001 From: kontrollanten <6680299+kontrollanten@users.noreply.github.com> Date: Fri, 4 Dec 2020 22:13:11 +0100 Subject: [PATCH] server/mw/oauth: res.loc.auth to true upon auth Setting res.locals.authenticated explicity to true makes it's more clear whether the req is authenticated when using optionalAuthenticate middlware. --- server/middlewares/oauth.ts | 2 ++ server/tests/plugins/plugin-router.ts | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/server/middlewares/oauth.ts b/server/middlewares/oauth.ts index ab5301415..ffc1b7ca9 100644 --- a/server/middlewares/oauth.ts +++ b/server/middlewares/oauth.ts @@ -20,6 +20,8 @@ function authenticate (req: express.Request, res: express.Response, next: expres .end() } + res.locals.authenticated = true + return next() }) } diff --git a/server/tests/plugins/plugin-router.ts b/server/tests/plugins/plugin-router.ts index 5392acc51..24e6a1e83 100644 --- a/server/tests/plugins/plugin-router.ts +++ b/server/tests/plugins/plugin-router.ts @@ -53,7 +53,7 @@ describe('Test plugin helpers', function () { statusCodeExpected: 200 }) - expect(res.body.isAuthenticated).to.equal(undefined) + expect(res.body.isAuthenticated).to.equal(true) const secRes = await makeGetRequest({ url: server.url,