Merge branch 'feature/backend-routing' of github.com:Budibase/budibase into component-sdk
This commit is contained in:
commit
342b310cd1
|
@ -1,7 +1,9 @@
|
||||||
const jwt = require("jsonwebtoken")
|
const jwt = require("jsonwebtoken")
|
||||||
const STATUS_CODES = require("../utilities/statusCodes")
|
const STATUS_CODES = require("../utilities/statusCodes")
|
||||||
const { getAccessLevel, BUILTIN_LEVELS } = require("../utilities/security/accessLevels")
|
const {
|
||||||
const env = require("../environment")
|
getAccessLevel,
|
||||||
|
BUILTIN_LEVELS,
|
||||||
|
} = require("../utilities/security/accessLevels")
|
||||||
const { AuthTypes } = require("../constants")
|
const { AuthTypes } = require("../constants")
|
||||||
const { getAppId, getCookieName, setCookie, isClient } = require("../utilities")
|
const { getAppId, getCookieName, setCookie, isClient } = require("../utilities")
|
||||||
|
|
||||||
|
@ -21,12 +23,10 @@ module.exports = async (ctx, next) => {
|
||||||
appId = cookieAppId
|
appId = cookieAppId
|
||||||
}
|
}
|
||||||
|
|
||||||
let token
|
let token = ctx.cookies.get(getCookieName(appId))
|
||||||
if (isClient(ctx)) {
|
let authType = AuthTypes.APP
|
||||||
ctx.auth.authenticated = AuthTypes.APP
|
if (!token && !isClient(ctx)) {
|
||||||
token = ctx.cookies.get(getCookieName(appId))
|
authType = AuthTypes.BUILDER
|
||||||
} else {
|
|
||||||
ctx.auth.authenticated = AuthTypes.BUILDER
|
|
||||||
token = ctx.cookies.get(getCookieName())
|
token = ctx.cookies.get(getCookieName())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,6 +42,7 @@ module.exports = async (ctx, next) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
ctx.auth.authenticated = authType
|
||||||
const jwtPayload = jwt.verify(token, ctx.config.jwtSecret)
|
const jwtPayload = jwt.verify(token, ctx.config.jwtSecret)
|
||||||
ctx.appId = appId
|
ctx.appId = appId
|
||||||
ctx.auth.apiKey = jwtPayload.apiKey
|
ctx.auth.apiKey = jwtPayload.apiKey
|
||||||
|
|
Loading…
Reference in New Issue