Skip to content

Commit

Permalink
Merge pull request #2211 from owncloud/bugfix/no-full-reinit-on-token…
Browse files Browse the repository at this point in the history
…-refresh

Upon token refresh do not perform full login on sdk level - this woul…
  • Loading branch information
DeepDiver1975 authored Oct 10, 2019
2 parents d1b7867 + 8527488 commit ccd4756
Showing 1 changed file with 31 additions and 24 deletions.
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

0 comments on commit ccd4756

Please sign in to comment.