Skip to content

Commit e5cec3b

Browse files
committed
don't set req.session twice
1 parent 8db3307 commit e5cec3b

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/middlewares/base-handler.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ export function createBaseHandler() {
6060

6161
// Add session to request
6262
baseHandler.use(async (req, res, next) => {
63+
/** Handle authorization using either Bearer token auth or
64+
* using the next-auth session
65+
*/
6366
if (req.headers.authorization) {
6467
// introspect the token
6568
const [type, token] = req.headers.authorization.split(' ')
@@ -86,10 +89,11 @@ export function createBaseHandler() {
8689
throw Boom.badRequest('Invalid token')
8790
}
8891
}
89-
}
90-
const token = await getToken({ req })
91-
if (token) {
92-
req.session = { user_id: token.userId || token.sub }
92+
} else {
93+
const token = await getToken({ req })
94+
if (token) {
95+
req.session = { user_id: token.userId || token.sub }
96+
}
9397
}
9498
next()
9599
})

0 commit comments

Comments
 (0)