diff --git a/packages/client/src/components/app/UserMenu.svelte b/packages/client/src/components/app/UserMenu.svelte index 57dd5e9f5c..df451742c3 100644 --- a/packages/client/src/components/app/UserMenu.svelte +++ b/packages/client/src/components/app/UserMenu.svelte @@ -3,14 +3,16 @@ import { UserAvatar } from "@budibase/frontend-core" import { getContext } from "svelte" import { User, ContextUser } from "@budibase/types" + import { sdk } from "@budibase/shared-core" export let compact: boolean = false const { authStore } = getContext("sdk") $: text = getText($authStore) + $: isBuilder = sdk.users.hasBuilderPermissions($authStore) - const getText = (user: User | ContextUser | null): string => { + const getText = (user?: User | ContextUser): string => { if (!user) { return "" } @@ -26,7 +28,7 @@ } const goToPortal = () => { - window.location.href = "/builder/apps" + window.location.href = isBuilder ? "/builder/portal/apps" : "/builder/apps" } diff --git a/packages/client/src/stores/auth.ts b/packages/client/src/stores/auth.ts index f29ff3a124..9728cc52fc 100644 --- a/packages/client/src/stores/auth.ts +++ b/packages/client/src/stores/auth.ts @@ -6,10 +6,10 @@ import { GetGlobalSelfResponse, } from "@budibase/types" -type AuthState = ContextUserMetadata | GetGlobalSelfResponse | null +type AuthState = ContextUserMetadata | GetGlobalSelfResponse | undefined const createAuthStore = () => { - const store = writable(null) + const store = writable() const hasAppSelfUser = ( user: AppSelfResponse | null @@ -19,14 +19,13 @@ const createAuthStore = () => { // Fetches the user object if someone is logged in and has reloaded the page const fetchUser = async () => { - let globalSelf = null - let appSelf = null + let globalSelf, appSelf // First try and get the global user, to see if we are logged in at all try { globalSelf = await API.fetchBuilderSelf() } catch (error) { - store.set(null) + store.set(undefined) return } @@ -41,7 +40,7 @@ const createAuthStore = () => { } // Use the app self if present, otherwise fallback to the global self - store.set(appSelf || globalSelf || null) + store.set(appSelf || globalSelf) } const logOut = async () => {