[update]校验登录状态

This commit is contained in:
OrangeM21
2020-05-27 20:48:09 +08:00
parent a23de329ba
commit cb73c2cb5e
2 changed files with 16 additions and 7 deletions

View File

@@ -77,7 +77,7 @@ router.beforeEach(async(to, from, next) => {
// remove token and go to login page to re-login
// await store.dispatch('user/resetToken')
Message.error(error || 'Has Error')
// next(`/login?redirect=${to.path}`)
next(`/auth/login/`)
console.log(error)
NProgress.done()
// next()

View File

@@ -11,7 +11,8 @@ const getDefaultState = () => {
token: getToken(),
profile: {},
currentOrg: getCurrentOrg(),
orgs: []
orgs: [],
internalInit: Boolean
}
}
@@ -27,6 +28,9 @@ const mutations = {
SET_PROFILE: (state, profile) => {
state.profile = profile
},
SET_STATUS: (state) => {
state.internalInit = true
},
SET_ORGS: (state, orgs) => {
// API BUG FIX
for (let index = 0; index < orgs.length; index++) {
@@ -61,18 +65,23 @@ const actions = {
// get user Profile
getProfile({ commit, state }) {
return new Promise((resolve, reject) => {
if (!state.internalInit) {
reject('Init failed, please Login again.')
}
getProfile().then(response => {
if (!response) {
reject('Verification failed, please Login again.')
}
const { admin_or_audit_orgs } = response
// const rules = [role]
const { admin_or_audit_orgs, rule } = response
const rules = [rule]
// roles must be a non-empty array
// if (!rules || rules.length <= 0) {
// reject('getProfile: roles must be a non-null array!')
// }
if (!rules || rules.length <= 0) {
reject('getProfile: roles must be a non-null array!')
}
commit('SET_PROFILE', response)
commit('SET_ORGS', admin_or_audit_orgs)
commit('SET_STATUS')
resolve(response)
}).catch(error => {
reject(error)