1
0
Fork 0
mirror of synced 2024-07-07 15:25:52 +12:00

Fix error with refreshing app package so that page reload on logout can be prevented

This commit is contained in:
Andrew Kingston 2021-07-25 13:43:07 +01:00
parent 7107b6aff3
commit 59bfba4331
2 changed files with 23 additions and 3 deletions

View file

@ -6,8 +6,15 @@ const createAppStore = () => {
// Fetches the app definition including screens, layouts and theme // Fetches the app definition including screens, layouts and theme
const fetchAppDefinition = async () => { const fetchAppDefinition = async () => {
const appDefinition = await API.fetchAppPackage(get(store).appId) const appId = get(store)?.appId
store.set(appDefinition) if (!appId) {
throw "Cannot fetch app definition without app ID set"
}
const appDefinition = await API.fetchAppPackage(appId)
store.set({
...appDefinition,
appId: appDefinition?.application?.appId,
})
} }
// Sets the initial app ID // Sets the initial app ID

View file

@ -1,9 +1,20 @@
import * as API from "../api" import * as API from "../api"
import { writable } from "svelte/store" import { writable } from "svelte/store"
import { initialise } from "./initialise"
import { routeStore } from "./routes"
const createAuthStore = () => { const createAuthStore = () => {
const store = writable(null) const store = writable(null)
const goToDefaultRoute = () => {
// Setting the active route forces an update of the active screen ID,
// even if we're on the same URL
routeStore.actions.setActiveRoute("/")
// Navigating updates the URL to reflect this route
routeStore.actions.navigate("/")
}
// 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 () => {
const user = await API.fetchSelf() const user = await API.fetchSelf()
@ -11,8 +22,10 @@ const createAuthStore = () => {
} }
const logOut = async () => { const logOut = async () => {
store.set(null)
window.document.cookie = `budibase:auth=; budibase:currentapp=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;` window.document.cookie = `budibase:auth=; budibase:currentapp=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;`
window.location.reload() await initialise()
goToDefaultRoute()
} }
return { return {