A lot
This commit is contained in:
@@ -3,6 +3,7 @@ import axios from 'axios'
|
||||
|
||||
// initial state
|
||||
const state = () => ({
|
||||
isReady: false,
|
||||
isLoggedIn: false,
|
||||
isAdmin: false,
|
||||
accessToken: null,
|
||||
@@ -11,7 +12,8 @@ const state = () => ({
|
||||
displayName: null,
|
||||
|
||||
debugFullTokenResponse: null,
|
||||
debugAccountInfo: null,
|
||||
// debugAccountInfo: null,
|
||||
onReady: [],
|
||||
})
|
||||
|
||||
// getters
|
||||
@@ -30,12 +32,19 @@ const actions = {
|
||||
Authorization: `Bearer ${state.idToken}`,
|
||||
},
|
||||
})
|
||||
.then(res => (isAdmin = res.data))
|
||||
.catch(error => console.error(error))
|
||||
.then((res) => (isAdmin = res.data))
|
||||
.catch((error) => console.error(error))
|
||||
}
|
||||
commit('setState', { ...state, isAdmin })
|
||||
})
|
||||
},
|
||||
async waitTillReady({ commit, state }) {
|
||||
if (!state.isReady) {
|
||||
await new Promise((c) => {
|
||||
commit('addReadyCalback', c)
|
||||
})
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
// mutations
|
||||
@@ -46,9 +55,16 @@ const mutations = {
|
||||
state.accessToken = msalState.accessToken
|
||||
state.idToken = msalState.idToken
|
||||
state.debugFullTokenResponse = msalState.debugFullTokenResponse
|
||||
state.debugAccountInfo = msalState.debugAccountInfo
|
||||
// state.debugAccountInfo = msalState.debugAccountInfo
|
||||
state.email = msalState.email
|
||||
state.displayName = msalState.displayName
|
||||
if (!state.isReady && state.idToken) {
|
||||
state.isReady = true
|
||||
state.onReady.forEach((c) => c())
|
||||
}
|
||||
},
|
||||
addReadyCalback(state, callback) {
|
||||
state.onReady.push(callback)
|
||||
},
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user