Some stuff

This commit is contained in:
Karolis2011
2021-12-22 22:50:09 +02:00
parent 997154efa8
commit cad4268b79
11 changed files with 236 additions and 36 deletions

View File

@@ -1,8 +1,10 @@
import { WatchMsalState, GetMsalState } from '@/msal'
import axios from 'axios'
// initial state
const state = () => ({
isLoggedIn: false,
isAdmin: false,
accessToken: null,
idToken: null,
email: null,
@@ -18,8 +20,20 @@ const getters = {}
// actions
const actions = {
initialize({ commit }) {
WatchMsalState(() => {
commit('setState', GetMsalState())
WatchMsalState(async () => {
const state = GetMsalState()
let isAdmin = false
if (state.isLoggedIn && state.idToken) {
await axios
.get('/api/AuthMetadata/Admin', {
headers: {
Authorization: `Bearer ${state.idToken}`,
},
})
.then(res => (isAdmin = res.data))
.catch(error => console.error(error))
}
commit('setState', { ...state, isAdmin })
})
},
}
@@ -28,6 +42,7 @@ const actions = {
const mutations = {
setState(state, msalState) {
state.isLoggedIn = msalState.isLoggedIn
state.isAdmin = msalState.isAdmin
state.accessToken = msalState.accessToken
state.idToken = msalState.idToken
state.debugFullTokenResponse = msalState.debugFullTokenResponse