1
0
Fork 0
mirror of synced 2024-06-29 19:41:03 +12:00

Use global self endpoint in client apps to differentiate between not being logged in and not having access to an app

This commit is contained in:
Andrew Kingston 2022-03-23 11:41:51 +00:00
parent e7ff1c4ba9
commit bd93f150b5

View file

@ -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 () => {