store tenant in cookie for use in account portal

This commit is contained in:
Peter Clement 2024-02-13 15:26:22 +00:00
parent 353ab4b1be
commit d508e8f01b
3 changed files with 17 additions and 5 deletions

@ -1 +1 @@
Subproject commit aaf64dd002a7d2b9ff37f989e03d444c9b9f2b36
Subproject commit 50864c77a7c82e7b3f0d1dcfe6ac29d4a0173726

View File

@ -1,6 +1,7 @@
<script>
import { auth, admin } from "stores/portal"
import { redirect } from "@roxi/routify"
import { CookieUtils } from "@budibase/frontend-core"
// If already authenticated, redirect away from the auth section.
// Check this onMount rather than a reactive statement to avoid trumping
@ -9,13 +10,20 @@
$redirect("../")
}
if ($admin.checklist?.branding) {
let url = new URL("http://hello.petertest.com:10001/auth/login")
let hostname = url.hostname
let parts = hostname.split(".")
let tenantId = parts[0]
CookieUtils.setCookie("tenantId", tenantId, "petertest.com")
}
if (
!$auth.user &&
$admin.cloud &&
!$admin.disableAccountPortal &&
$admin.accountPortalUrl &&
!$admin?.checklist?.sso?.checked &&
!$admin.checklist.branding
!$admin?.checklist?.sso?.checked
) {
window.location.href = $admin.accountPortalUrl
}

View File

@ -1,8 +1,12 @@
export function setCookie(name, value) {
export function setCookie(name, value, domain) {
if (getCookie(name)) {
removeCookie(name)
}
window.document.cookie = `${name}=${value}; Path=/;`
let cookieString = `${name}=${value}; Path=/;`
if (domain) {
cookieString += ` Domain=${domain};`
}
window.document.cookie = cookieString
}
export function getCookie(cookieName) {