cookie based approach
This commit is contained in:
parent
24805b183b
commit
7cead2d8f4
|
@ -6,6 +6,7 @@ exports.UserStatus = {
|
||||||
exports.Cookies = {
|
exports.Cookies = {
|
||||||
CurrentApp: "budibase:currentapp",
|
CurrentApp: "budibase:currentapp",
|
||||||
Auth: "budibase:auth",
|
Auth: "budibase:auth",
|
||||||
|
Init: "budibase:init",
|
||||||
OIDC_CONFIG: "budibase:oidc:config",
|
OIDC_CONFIG: "budibase:oidc:config",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -139,7 +139,7 @@
|
||||||
}
|
}
|
||||||
const userResp = await api.post(`/api/users/metadata/self`, user)
|
const userResp = await api.post(`/api/users/metadata/self`, user)
|
||||||
await userResp.json()
|
await userResp.json()
|
||||||
auth.resetInitTemplate()
|
await auth.setInitInfo({})
|
||||||
$goto(`/builder/app/${appJson.instance._id}`)
|
$goto(`/builder/app/${appJson.instance._id}`)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error)
|
console.error(error)
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<script>
|
<script>
|
||||||
import { isActive, redirect } from "@roxi/routify"
|
import { isActive, redirect, params } from "@roxi/routify"
|
||||||
import { admin, auth } from "stores/portal"
|
import { admin, auth } from "stores/portal"
|
||||||
import { onMount } from "svelte"
|
import { onMount } from "svelte"
|
||||||
|
|
||||||
|
@ -47,6 +47,11 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
|
if ($params["?template"]) {
|
||||||
|
console.log("SETTING COOKIE", $params["?template"])
|
||||||
|
await auth.setInitInfo({ init_template: $params["?template"] })
|
||||||
|
}
|
||||||
|
|
||||||
await auth.checkAuth()
|
await auth.checkAuth()
|
||||||
await admin.init()
|
await admin.init()
|
||||||
|
|
||||||
|
|
|
@ -16,11 +16,7 @@
|
||||||
$admin.accountPortalUrl &&
|
$admin.accountPortalUrl &&
|
||||||
!$admin?.checklist?.sso?.checked
|
!$admin?.checklist?.sso?.checked
|
||||||
) {
|
) {
|
||||||
let url = $admin.accountPortalUrl
|
window.location.href = $admin.accountPortalUrl
|
||||||
if ($auth.initTemplate) {
|
|
||||||
url += `?template=${$auth.initTemplate}`
|
|
||||||
}
|
|
||||||
window.location.href = url
|
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
|
@ -201,9 +201,10 @@
|
||||||
await apps.load()
|
await apps.load()
|
||||||
loaded = true
|
loaded = true
|
||||||
// if the portal is loaded from an external URL with a template param
|
// if the portal is loaded from an external URL with a template param
|
||||||
const templateKey = $auth.initTemplate
|
const initInfo = await auth.getInitInfo()
|
||||||
if (templateKey) {
|
console.log(initInfo)
|
||||||
createAppFromTemplateUrl(templateKey)
|
if (initInfo.init_template) {
|
||||||
|
createAppFromTemplateUrl(initInfo.init_template)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -33,7 +33,6 @@ export function createAuthStore() {
|
||||||
user: $store.user,
|
user: $store.user,
|
||||||
tenantId: $store.tenantId,
|
tenantId: $store.tenantId,
|
||||||
tenantSet: $store.tenantSet,
|
tenantSet: $store.tenantSet,
|
||||||
initTemplate: $store.initTemplate,
|
|
||||||
loaded: $store.loaded,
|
loaded: $store.loaded,
|
||||||
initials,
|
initials,
|
||||||
isAdmin,
|
isAdmin,
|
||||||
|
@ -81,28 +80,22 @@ export function createAuthStore() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateInitTemplate(template) {
|
|
||||||
auth.update(store => {
|
|
||||||
store.initTemplate = template
|
|
||||||
return store
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
subscribe: store.subscribe,
|
subscribe: store.subscribe,
|
||||||
resetInitTemplate: () => updateInitTemplate(null),
|
|
||||||
setOrganisation: setOrganisation,
|
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 () => {
|
checkQueryString: async () => {
|
||||||
const urlParams = new URLSearchParams(window.location.search)
|
const urlParams = new URLSearchParams(window.location.search)
|
||||||
if (urlParams.has("tenantId")) {
|
if (urlParams.has("tenantId")) {
|
||||||
const tenantId = urlParams.get("tenantId")
|
const tenantId = urlParams.get("tenantId")
|
||||||
await setOrganisation(tenantId)
|
await setOrganisation(tenantId)
|
||||||
}
|
}
|
||||||
|
|
||||||
// set the template to create an app from
|
|
||||||
if (urlParams.has("template")) {
|
|
||||||
updateInitTemplate(urlParams.get("template"))
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
setOrg: async tenantId => {
|
setOrg: async tenantId => {
|
||||||
await setOrganisation(tenantId)
|
await setOrganisation(tenantId)
|
||||||
|
|
|
@ -77,6 +77,17 @@ exports.authenticate = async (ctx, next) => {
|
||||||
})(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.
|
* Reset the user password, used as part of a forgotten password flow.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -56,6 +56,8 @@ router
|
||||||
authController.resetUpdate
|
authController.resetUpdate
|
||||||
)
|
)
|
||||||
.post("/api/global/auth/logout", authController.logout)
|
.post("/api/global/auth/logout", authController.logout)
|
||||||
|
.post("/api/global/auth/init", authController.setInitInfo)
|
||||||
|
.get("/api/global/auth/init", authController.getInitInfo)
|
||||||
.get(
|
.get(
|
||||||
"/api/global/auth/:tenantId/google",
|
"/api/global/auth/:tenantId/google",
|
||||||
updateTenant,
|
updateTenant,
|
||||||
|
|
Loading…
Reference in New Issue