further simplification of jwt auth

This commit is contained in:
Martin McKeaveney 2021-04-08 11:53:40 +01:00
parent fb2fda4055
commit 4abe6192dc
1 changed files with 4 additions and 18 deletions

View File

@ -11,29 +11,15 @@ module.exports = async (ctx, next) => {
appId = cookieAppId
}
let token
if (appId) {
token = ctx.cookies.get(Cookies.Auth)
}
if (!token) {
ctx.auth = {
authenticated: false,
}
ctx.appId = appId
// ctx.user = {
// // TODO: introduce roles again
// // role: builtinRoles.PUBLIC,
// }
return await next()
}
return passport.authenticate("jwt", async (err, user) => {
if (err) {
return ctx.throw(err)
return ctx.throw(err.status || 403, err)
}
try {
ctx.appId = appId
ctx.isAuthenticated = true
// TODO: introduce roles again
ctx.user = user
await next()
} catch (err) {