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:
parent
3817de254e
commit
bd487fa988
|
@ -6,12 +6,26 @@ const createAuthStore = () => {
|
||||||
|
|
||||||
// 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 () => {
|
||||||
|
let globalSelf = null
|
||||||
|
let appSelf = null
|
||||||
|
|
||||||
|
// First try and get the global user, to see if we are logged in at all
|
||||||
try {
|
try {
|
||||||
const user = await API.fetchSelf()
|
globalSelf = await API.fetchBuilderSelf()
|
||||||
store.set(user)
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
store.set(null)
|
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 () => {
|
const logOut = async () => {
|
||||||
|
|
Loading…
Reference in New Issue