Update go to portal link to reflect builder status and update types of auth store slightly
This commit is contained in:
parent
2e831251f8
commit
b390f92019
|
@ -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"
|
||||
}
|
||||
</script>
|
||||
|
||||
|
|
|
@ -6,10 +6,10 @@ import {
|
|||
GetGlobalSelfResponse,
|
||||
} from "@budibase/types"
|
||||
|
||||
type AuthState = ContextUserMetadata | GetGlobalSelfResponse | null
|
||||
type AuthState = ContextUserMetadata | GetGlobalSelfResponse | undefined
|
||||
|
||||
const createAuthStore = () => {
|
||||
const store = writable<AuthState>(null)
|
||||
const store = writable<AuthState>()
|
||||
|
||||
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 () => {
|
||||
|
|
Loading…
Reference in New Issue