1
0
Fork 0
mirror of synced 2024-06-30 03:50:37 +12:00

more auth bugfixes

This commit is contained in:
Martin McKeaveney 2020-10-15 14:26:33 +01:00
parent 3ba8f19e7f
commit 8a936e0927
2 changed files with 7 additions and 3 deletions

View file

@ -3,6 +3,8 @@ export const parseAppIdFromCookie = docCookie => {
docCookie.split(";").find(c => c.trim().startsWith("budibase:token")) ||
docCookie.split(";").find(c => c.trim().startsWith("builder:token"))
if (!cookie) return location.pathname.replace("/")
const base64Token = cookie.substring(lengthOfKey)
const user = JSON.parse(atob(base64Token.split(".")[1]))

View file

@ -34,12 +34,14 @@ module.exports = async (ctx, next) => {
let appId = process.env.CLOUD ? ctx.subdomains[1] : ctx.params.appId
if (!appId) {
appId = ctx.referer && ctx.referer.split("/").pop()
// if appId can't be determined from path param or subdomain
if (!appId && ctx.request.headers.referer) {
const url = new URL(ctx.request.headers.referer)
// remove leading and trailing slashes from appId
appId = url.pathname.replace(/\//g, "")
}
ctx.user = {
// if appId can't be determined from path param or subdomain
appId,
}
await next()