From 95d05c8a8e4f02cb2f2fa562176cfc0c46f31696 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Sun, 25 Jul 2021 13:43:07 +0100 Subject: [PATCH] Fix error with refreshing app package so that page reload on logout can be prevented --- packages/client/src/store/app.js | 11 +++++++++-- packages/client/src/store/auth.js | 15 ++++++++++++++- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/packages/client/src/store/app.js b/packages/client/src/store/app.js index eb5a259a25..0cabaec4ab 100644 --- a/packages/client/src/store/app.js +++ b/packages/client/src/store/app.js @@ -6,8 +6,15 @@ const createAppStore = () => { // Fetches the app definition including screens, layouts and theme const fetchAppDefinition = async () => { - const appDefinition = await API.fetchAppPackage(get(store).appId) - store.set(appDefinition) + const appId = get(store)?.appId + 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 diff --git a/packages/client/src/store/auth.js b/packages/client/src/store/auth.js index beaeb6007c..86e4500282 100644 --- a/packages/client/src/store/auth.js +++ b/packages/client/src/store/auth.js @@ -1,9 +1,20 @@ import * as API from "../api" import { writable } from "svelte/store" +import { initialise } from "./initialise" +import { routeStore } from "./routes" const createAuthStore = () => { 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 const fetchUser = async () => { const user = await API.fetchSelf() @@ -11,8 +22,10 @@ const createAuthStore = () => { } const logOut = async () => { + store.set(null) window.document.cookie = `budibase:auth=; budibase:currentapp=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;` - window.location.reload() + await initialise() + goToDefaultRoute() } return {