1
0
Fork 0
mirror of synced 2024-06-30 20:10:54 +12:00

further simplification of jwt auth

This commit is contained in:
Martin McKeaveney 2021-04-08 11:53:40 +01:00
parent fb2fda4055
commit 4abe6192dc

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) {