diff --git a/src/services/auth.js b/src/services/auth.js index 12c512ae518..daa79a290ad 100644 --- a/src/services/auth.js +++ b/src/services/auth.js @@ -58,15 +58,6 @@ export function initVueAuthenticate (config) { Log.logger = console Log.level = openIdConfig.logLevel - mgr.events.addUserLoaded(function (user) { - console.log('New User Loaded:', arguments) - console.log('Access_token: ', user.access_token) - }) - - mgr.events.addSilentRenewError(function () { - console.error('Silent Renew Error:', arguments) - }) - mgr.events.addUserSignedOut(function () { console.log('UserSignedOut:', arguments) }) diff --git a/src/store/user.js b/src/store/user.js index 4f6c448480c..d513a76805e 100644 --- a/src/store/user.js +++ b/src/store/user.js @@ -16,6 +16,9 @@ const state = { const actions = { cleanUpLoginState (context) { + if (context.state.id === '') { + return + } // reset user to default state context.commit('SET_USER', state) // reset capabilities to default state @@ -37,10 +40,6 @@ const actions = { }) }, initAuth (context, payload = { autoRedirect: false }) { - // if called from login, use available vue-authenticate instance; else re-init - if (!vueAuthInstance) vueAuthInstance = initVueAuthenticate(context.rootState.config) - const token = vueAuthInstance.getToken() - function init (client, token) { const instance = context.rootState.config.server || window.location.origin const options = { @@ -87,28 +86,33 @@ const actions = { }) } - const tokenRefresh = function (client) { - vueAuthInstance.mgr.signinSilent().then(user => { - console.log('token refreshed…') - init(client, user.access_token) - }).catch(error => { - console.warn('token refresh failed ' + error) - context.dispatch('cleanUpLoginState') - router.push({ name: 'accessDenied' }) - }) - } - - if (token) { + // if called from login, use available vue-authenticate instance; else re-init + if (!vueAuthInstance) { + vueAuthInstance = initVueAuthenticate(context.rootState.config) const client = this._vm.$client vueAuthInstance.events().addAccessTokenExpired(function () { - console.log('store/user.js - AccessToken Expired:', arguments) - tokenRefresh(client) + console.log('AccessToken Expired:', arguments) }) vueAuthInstance.mgr.events.addAccessTokenExpiring(function () { console.log('AccessToken Expiring:', arguments) - tokenRefresh(client) }) - + vueAuthInstance.events().addUserLoaded(user => { + console.log(`New User Loaded. access_token: ${user.access_token}, refresh_token: ${user.refresh_token}`) + init(client, user.access_token) + }) + vueAuthInstance.events().addUserUnloaded(() => { + console.log('user unloaded…') + context.dispatch('cleanUpLoginState') + router.push({ name: 'accessDenied' }) + }) + vueAuthInstance.events().addSilentRenewError(error => { + console.error('Silent Renew Error:', error) + context.dispatch('cleanUpLoginState') + router.push({ name: 'accessDenied' }) + }) + } + const token = vueAuthInstance.getToken() + if (token) { init(this._vm.$client, token) } },