mirror of
				https://github.com/veops/cmdb.git
				synced 2025-11-04 21:56:16 +08:00 
			
		
		
		
	fix(sso login): sso login redirect
This commit is contained in:
		@@ -1,8 +1,8 @@
 | 
			
		||||
import config from '@/config/defaultSettings'
 | 
			
		||||
 | 
			
		||||
const api = {
 | 
			
		||||
  Login: config.useSSO ? '/api/sso/login' : '/login',
 | 
			
		||||
  Logout: config.useSSO ? '/api/sso/logout' : '/logout',
 | 
			
		||||
  Login: config.useSSO ? config.ssoLoginRedirectUrl : '/login',
 | 
			
		||||
  Logout: config.useSSO ? config.ssoLogoutRedirectUrl : '/logout',
 | 
			
		||||
  ForgePassword: '/auth/forge-password',
 | 
			
		||||
  Register: '/auth/register',
 | 
			
		||||
  twoStepCode: '/auth/2step-code',
 | 
			
		||||
 
 | 
			
		||||
@@ -39,9 +39,10 @@ export function getInfo () {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export function logout () {
 | 
			
		||||
  console.log('logout........')
 | 
			
		||||
  console.log('logout........', config.useSSO)
 | 
			
		||||
  if (config.useSSO) {
 | 
			
		||||
    window.location.replace(api.Logout)
 | 
			
		||||
    window.location.href = api.Logout
 | 
			
		||||
    return Promise.resolve()
 | 
			
		||||
  } else {
 | 
			
		||||
    return axios({
 | 
			
		||||
      url: api.Logout,
 | 
			
		||||
 
 | 
			
		||||
@@ -42,13 +42,13 @@ router.beforeEach((to, from, next) => {
 | 
			
		||||
        })
 | 
			
		||||
      })
 | 
			
		||||
      .catch((e) => {
 | 
			
		||||
        console.log(e)
 | 
			
		||||
        notification.error({
 | 
			
		||||
          message: this.$t('tip.error'),
 | 
			
		||||
          message: e.message,
 | 
			
		||||
          description: 'Failed to request user information. Please try again!'
 | 
			
		||||
        })
 | 
			
		||||
        setTimeout(() => {
 | 
			
		||||
          store.dispatch('Logout')
 | 
			
		||||
          console.log('should re-login')
 | 
			
		||||
          store.dispatch('Login')
 | 
			
		||||
        }, 3000)
 | 
			
		||||
      })
 | 
			
		||||
  } else if (to.path === '/user/login' && !config.useSSO && store.getters.roles.length !== 0) {
 | 
			
		||||
 
 | 
			
		||||
@@ -75,18 +75,10 @@ const user = {
 | 
			
		||||
 | 
			
		||||
    // logout
 | 
			
		||||
    Logout ({ commit, state }) {
 | 
			
		||||
      return new Promise((resolve) => {
 | 
			
		||||
        commit('SET_TOKEN', '')
 | 
			
		||||
        commit('SET_ROLES', [])
 | 
			
		||||
        Vue.ls.remove(ACCESS_TOKEN)
 | 
			
		||||
 | 
			
		||||
        logout(state.token).then(() => {
 | 
			
		||||
          window.location.reload()
 | 
			
		||||
          resolve()
 | 
			
		||||
        }).catch(() => {
 | 
			
		||||
          resolve()
 | 
			
		||||
        })
 | 
			
		||||
      })
 | 
			
		||||
      commit('SET_TOKEN', '')
 | 
			
		||||
      commit('SET_ROLES', [])
 | 
			
		||||
      Vue.ls.remove(ACCESS_TOKEN)
 | 
			
		||||
      return logout(state.token)
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
  }
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user