1
0
Fork 0
mirror of synced 2024-07-05 14:31:17 +12:00

Merge branch 'component-sdk' of github.com:Budibase/budibase into component-sdk

This commit is contained in:
Andrew Kingston 2020-11-20 09:50:25 +00:00
commit bb46d1e139

View file

@ -1,7 +1,9 @@
const jwt = require("jsonwebtoken")
const STATUS_CODES = require("../utilities/statusCodes")
const { getAccessLevel, BUILTIN_LEVELS } = require("../utilities/security/accessLevels")
const env = require("../environment")
const {
getAccessLevel,
BUILTIN_LEVELS,
} = require("../utilities/security/accessLevels")
const { AuthTypes } = require("../constants")
const { getAppId, getCookieName, setCookie, isClient } = require("../utilities")
@ -21,12 +23,10 @@ module.exports = async (ctx, next) => {
appId = cookieAppId
}
let token
if (isClient(ctx)) {
ctx.auth.authenticated = AuthTypes.APP
token = ctx.cookies.get(getCookieName(appId))
} else {
ctx.auth.authenticated = AuthTypes.BUILDER
let token = ctx.cookies.get(getCookieName(appId))
let authType = AuthTypes.APP
if (!token && !isClient(ctx)) {
authType = AuthTypes.BUILDER
token = ctx.cookies.get(getCookieName())
}
@ -42,6 +42,7 @@ module.exports = async (ctx, next) => {
}
try {
ctx.auth.authenticated = authType
const jwtPayload = jwt.verify(token, ctx.config.jwtSecret)
ctx.appId = appId
ctx.auth.apiKey = jwtPayload.apiKey