|
|
|
@ -20,8 +20,10 @@ module.exports = async (ctx, next) => { |
|
|
|
if (builderToken) { |
|
|
|
try { |
|
|
|
const jwtPayload = jwt.verify(builderToken, ctx.config.jwtSecret) |
|
|
|
ctx.apiKey = jwtPayload.apiKey |
|
|
|
ctx.isAuthenticated = jwtPayload.accessLevelId === BUILDER_LEVEL_ID |
|
|
|
ctx.auth = { |
|
|
|
apiKey: jwtPayload.apiKey, |
|
|
|
authenticated: jwtPayload.accessLevelId === BUILDER_LEVEL_ID, |
|
|
|
} |
|
|
|
ctx.user = { |
|
|
|
...jwtPayload, |
|
|
|
accessLevel: await getAccessLevel( |
|
|
|
@ -38,14 +40,13 @@ module.exports = async (ctx, next) => { |
|
|
|
} |
|
|
|
|
|
|
|
if (!appToken) { |
|
|
|
ctx.isAuthenticated = false |
|
|
|
ctx.auth.authenticated = false |
|
|
|
await next() |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
try { |
|
|
|
const jwtPayload = jwt.verify(appToken, ctx.config.jwtSecret) |
|
|
|
ctx.apiKey = jwtPayload.apiKey |
|
|
|
ctx.user = { |
|
|
|
...jwtPayload, |
|
|
|
accessLevel: await getAccessLevel( |
|
|
|
@ -53,7 +54,10 @@ module.exports = async (ctx, next) => { |
|
|
|
jwtPayload.accessLevelId |
|
|
|
), |
|
|
|
} |
|
|
|
ctx.isAuthenticated = ctx.user.accessLevelId !== ANON_LEVEL_ID |
|
|
|
ctx.auth = { |
|
|
|
authenticated: ctx.user.accessLevelId !== ANON_LEVEL_ID, |
|
|
|
apiKey: jwtPayload.apiKey, |
|
|
|
} |
|
|
|
} catch (err) { |
|
|
|
ctx.throw(err.status || STATUS_CODES.FORBIDDEN, err.text) |
|
|
|
} |
|
|
|
|