Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upon token refresh do not perform full login on sdk level - this woul… #2211

Merged
merged 1 commit into from
Oct 10, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 31 additions & 24 deletions src/store/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const actions = {
})
},
initAuth (context, payload = { autoRedirect: false }) {
function init (client, token) {
function init (client, token, doLogin = true) {
const instance = context.rootState.config.server || window.location.origin
const options = {
baseUrl: instance,
Expand All @@ -60,30 +60,34 @@ const actions = {
}

client.init(options)
return client.login().then(res => {
return client.getCapabilities()
.then(cap => {
client.users.getUserGroups(res.id).then(groups => {
context.commit('SET_CAPABILITIES', cap)
context.commit('SET_USER', {
id: res.id,
displayname: res['display-name'],
email: !Object.keys(res.email).length ? '' : res.email,
token,
isAuthenticated: true,
groups: groups
})
if (doLogin) {
return client.login().then(res => {
return client.getCapabilities()
.then(cap => {
client.users.getUserGroups(res.id).then(groups => {
context.commit('SET_CAPABILITIES', cap)
context.commit('SET_USER', {
id: res.id,
displayname: res['display-name'],
email: !Object.keys(res.email).length ? '' : res.email,
token,
isAuthenticated: true,
groups: groups
})

if (payload.autoRedirect) {
router.push({ path: '/' })
}
if (payload.autoRedirect) {
router.push({ path: '/' })
}
})
})
})
}).catch((e) => {
console.warn('Seems that your token is invalid. Error:', e)
context.dispatch('cleanUpLoginState')
router.push({ name: 'accessDenied' })
})
}).catch((e) => {
console.warn('Seems that your token is invalid. Error:', e)
context.dispatch('cleanUpLoginState')
router.push({ name: 'accessDenied' })
})
} else {
context.commit('UPDATE_TOKEN', token)
}
}

// if called from login, use available vue-authenticate instance; else re-init
Expand All @@ -98,7 +102,7 @@ const actions = {
})
vueAuthInstance.events().addUserLoaded(user => {
console.log(`New User Loaded. access_token: ${user.access_token}, refresh_token: ${user.refresh_token}`)
init(client, user.access_token)
init(client, user.access_token, false)
})
vueAuthInstance.events().addUserUnloaded(() => {
console.log('user unloaded…')
Expand Down Expand Up @@ -156,6 +160,9 @@ const mutations = {
SET_CAPABILITIES (state, data) {
state.capabilities = data.capabilities
state.version = data.version
},
UPDATE_TOKEN (state, token) {
state.token = token
}
}

Expand Down