This commit is contained in:
Karolis2011
2021-12-23 06:42:40 +02:00
parent cad4268b79
commit b367854887
23 changed files with 4103 additions and 2049 deletions

View File

@@ -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)
},
}