From bd487fa988a4c4ff3bcb6368edf99313dae2efb4 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Wed, 23 Mar 2022 11:41:51 +0000 Subject: [PATCH] Use global self endpoint in client apps to differentiate between not being logged in and not having access to an app --- packages/client/src/stores/auth.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/packages/client/src/stores/auth.js b/packages/client/src/stores/auth.js index 39f11319cf..214cc7bce2 100644 --- a/packages/client/src/stores/auth.js +++ b/packages/client/src/stores/auth.js @@ -6,12 +6,26 @@ 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 + + // First try and get the global user, to see if we are logged in at all try { - const user = await API.fetchSelf() - store.set(user) + globalSelf = await API.fetchBuilderSelf() } catch (error) { store.set(null) + return } + + // Then try and get the user for this app to provide via context + try { + appSelf = await API.fetchSelf() + } catch (error) { + // Swallow + } + + // Use the app self if present, otherwise fallback to the global self + store.set(appSelf || globalSelf || null) } const logOut = async () => {