Update go to portal link to reflect builder status and update types of auth store slightly

This commit is contained in:
Andrew Kingston 2025-03-07 15:48:12 +00:00
parent 2e831251f8
commit b390f92019
No known key found for this signature in database
2 changed files with 9 additions and 8 deletions

View File

@ -3,14 +3,16 @@
import { UserAvatar } from "@budibase/frontend-core" import { UserAvatar } from "@budibase/frontend-core"
import { getContext } from "svelte" import { getContext } from "svelte"
import { User, ContextUser } from "@budibase/types" import { User, ContextUser } from "@budibase/types"
import { sdk } from "@budibase/shared-core"
export let compact: boolean = false export let compact: boolean = false
const { authStore } = getContext("sdk") const { authStore } = getContext("sdk")
$: text = getText($authStore) $: text = getText($authStore)
$: isBuilder = sdk.users.hasBuilderPermissions($authStore)
const getText = (user: User | ContextUser | null): string => { const getText = (user?: User | ContextUser): string => {
if (!user) { if (!user) {
return "" return ""
} }
@ -26,7 +28,7 @@
} }
const goToPortal = () => { const goToPortal = () => {
window.location.href = "/builder/apps" window.location.href = isBuilder ? "/builder/portal/apps" : "/builder/apps"
} }
</script> </script>

View File

@ -6,10 +6,10 @@ import {
GetGlobalSelfResponse, GetGlobalSelfResponse,
} from "@budibase/types" } from "@budibase/types"
type AuthState = ContextUserMetadata | GetGlobalSelfResponse | null type AuthState = ContextUserMetadata | GetGlobalSelfResponse | undefined
const createAuthStore = () => { const createAuthStore = () => {
const store = writable<AuthState>(null) const store = writable<AuthState>()
const hasAppSelfUser = ( const hasAppSelfUser = (
user: AppSelfResponse | null user: AppSelfResponse | null
@ -19,14 +19,13 @@ const createAuthStore = () => {
// Fetches the user object if someone is logged in and has reloaded the page // Fetches the user object if someone is logged in and has reloaded the page
const fetchUser = async () => { const fetchUser = async () => {
let globalSelf = null let globalSelf, appSelf
let appSelf = null
// First try and get the global user, to see if we are logged in at all // First try and get the global user, to see if we are logged in at all
try { try {
globalSelf = await API.fetchBuilderSelf() globalSelf = await API.fetchBuilderSelf()
} catch (error) { } catch (error) {
store.set(null) store.set(undefined)
return return
} }
@ -41,7 +40,7 @@ const createAuthStore = () => {
} }
// Use the app self if present, otherwise fallback to the global self // Use the app self if present, otherwise fallback to the global self
store.set(appSelf || globalSelf || null) store.set(appSelf || globalSelf)
} }
const logOut = async () => { const logOut = async () => {