1
0
Fork 0
mirror of synced 2024-07-06 15:00:49 +12:00

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> <script>
import { auth, admin } from "stores/portal" import { auth, admin } from "stores/portal"
import { redirect } from "@roxi/routify" import { redirect } from "@roxi/routify"
import { CookieUtils } from "@budibase/frontend-core"
// If already authenticated, redirect away from the auth section. // If already authenticated, redirect away from the auth section.
// Check this onMount rather than a reactive statement to avoid trumping // Check this onMount rather than a reactive statement to avoid trumping
@ -9,13 +10,20 @@
$redirect("../") $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 ( if (
!$auth.user && !$auth.user &&
$admin.cloud && $admin.cloud &&
!$admin.disableAccountPortal && !$admin.disableAccountPortal &&
$admin.accountPortalUrl && $admin.accountPortalUrl &&
!$admin?.checklist?.sso?.checked && !$admin?.checklist?.sso?.checked
!$admin.checklist.branding
) { ) {
window.location.href = $admin.accountPortalUrl 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)) { if (getCookie(name)) {
removeCookie(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) { export function getCookie(cookieName) {