1
0
Fork 0
mirror of synced 2024-06-01 18:20:18 +12:00

cookie based approach

This commit is contained in:
Martin McKeaveney 2021-11-04 14:03:18 +01:00
parent b7d99a6df1
commit b80a93d6d5
8 changed files with 33 additions and 24 deletions

View file

@ -6,6 +6,7 @@ exports.UserStatus = {
exports.Cookies = {
CurrentApp: "budibase:currentapp",
Auth: "budibase:auth",
Init: "budibase:init",
OIDC_CONFIG: "budibase:oidc:config",
}

View file

@ -139,7 +139,7 @@
}
const userResp = await api.post(`/api/users/metadata/self`, user)
await userResp.json()
auth.resetInitTemplate()
await auth.setInitInfo({})
$goto(`/builder/app/${appJson.instance._id}`)
} catch (error) {
console.error(error)

View file

@ -1,5 +1,5 @@
<script>
import { isActive, redirect } from "@roxi/routify"
import { isActive, redirect, params } from "@roxi/routify"
import { admin, auth } from "stores/portal"
import { onMount } from "svelte"
@ -47,6 +47,11 @@
}
onMount(async () => {
if ($params["?template"]) {
console.log("SETTING COOKIE", $params["?template"])
await auth.setInitInfo({ init_template: $params["?template"] })
}
await auth.checkAuth()
await admin.init()

View file

@ -16,11 +16,7 @@
$admin.accountPortalUrl &&
!$admin?.checklist?.sso?.checked
) {
let url = $admin.accountPortalUrl
if ($auth.initTemplate) {
url += `?template=${$auth.initTemplate}`
}
window.location.href = url
window.location.href = $admin.accountPortalUrl
}
</script>

View file

@ -201,9 +201,10 @@
await apps.load()
loaded = true
// if the portal is loaded from an external URL with a template param
const templateKey = $auth.initTemplate
if (templateKey) {
createAppFromTemplateUrl(templateKey)
const initInfo = await auth.getInitInfo()
console.log(initInfo)
if (initInfo.init_template) {
createAppFromTemplateUrl(initInfo.init_template)
}
})
</script>

View file

@ -33,7 +33,6 @@ export function createAuthStore() {
user: $store.user,
tenantId: $store.tenantId,
tenantSet: $store.tenantSet,
initTemplate: $store.initTemplate,
loaded: $store.loaded,
initials,
isAdmin,
@ -81,28 +80,22 @@ export function createAuthStore() {
}
}
function updateInitTemplate(template) {
auth.update(store => {
store.initTemplate = template
return store
})
}
return {
subscribe: store.subscribe,
resetInitTemplate: () => updateInitTemplate(null),
setOrganisation: setOrganisation,
getInitInfo: async () => {
const response = await api.get(`/api/global/auth/init`)
return await response.json()
},
setInitInfo: async info => {
await api.post(`/api/global/auth/init`, info)
},
checkQueryString: async () => {
const urlParams = new URLSearchParams(window.location.search)
if (urlParams.has("tenantId")) {
const tenantId = urlParams.get("tenantId")
await setOrganisation(tenantId)
}
// set the template to create an app from
if (urlParams.has("template")) {
updateInitTemplate(urlParams.get("template"))
}
},
setOrg: async tenantId => {
await setOrganisation(tenantId)

View file

@ -77,6 +77,17 @@ exports.authenticate = async (ctx, next) => {
})(ctx, next)
}
exports.setInitInfo = ctx => {
const initInfo = ctx.request.body
setCookie(ctx, initInfo, Cookies.Init)
ctx.status = 200
}
exports.getInitInfo = ctx => {
const initInfo = getCookie(ctx, Cookies.Init)
ctx.body = initInfo
}
/**
* Reset the user password, used as part of a forgotten password flow.
*/

View file

@ -56,6 +56,8 @@ router
authController.resetUpdate
)
.post("/api/global/auth/logout", authController.logout)
.post("/api/global/auth/init", authController.setInitInfo)
.get("/api/global/auth/init", authController.getInitInfo)
.get(
"/api/global/auth/:tenantId/google",
updateTenant,