三方登录
This commit is contained in:
parent
1b45cb6927
commit
51a6fcbfb9
|
@ -11,7 +11,7 @@ import openThirdLogin from './utils/openThirdLogin'
|
|||
|
||||
NProgress.configure({ showSpinner: false }) // NProgress Configuration
|
||||
|
||||
const allowList = ['thirdLogin', 'login', 'register', 'registerResult'] // no redirect allowList
|
||||
const allowList = ['login', 'Welcome'] // no redirect allowList
|
||||
const loginRoutePath = '/user/login'
|
||||
const defaultRoutePath = '/user/welcome'
|
||||
|
||||
|
@ -58,11 +58,11 @@ router.beforeEach((to, from, next) => {
|
|||
})
|
||||
// 失败时,获取用户信息失败时,调用登出,来清空历史保留信息
|
||||
store.dispatch('Logout').then(() => {
|
||||
// if (process.env.NODE_ENV === 'production') {
|
||||
// openThirdLogin()
|
||||
// } else {
|
||||
next({ path: loginRoutePath, query: { redirect: to.fullPath } })
|
||||
// }
|
||||
if (process.env.NODE_ENV === 'production') {
|
||||
openThirdLogin()
|
||||
} else {
|
||||
next({ path: loginRoutePath, query: { redirect: to.fullPath } })
|
||||
}
|
||||
})
|
||||
})
|
||||
} else {
|
||||
|
@ -74,11 +74,11 @@ router.beforeEach((to, from, next) => {
|
|||
// 在免登录名单,直接进入
|
||||
next()
|
||||
} else {
|
||||
// if (process.env.NODE_ENV === 'production') {
|
||||
// openThirdLogin()
|
||||
// } else {
|
||||
next({ path: loginRoutePath, query: { redirect: to.fullPath } })
|
||||
// }
|
||||
if (process.env.NODE_ENV === 'production') {
|
||||
openThirdLogin()
|
||||
} else {
|
||||
next({ path: loginRoutePath, query: { redirect: to.fullPath } })
|
||||
}
|
||||
NProgress.done() // if current page is login will not trigger afterEach hook, so manually handle it
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
export default () => {
|
||||
const redirectUri = window.location.origin + '/user/thirdLogin'
|
||||
const redirectUri = window.location.origin + '/user/welcome'
|
||||
window.location.href =
|
||||
window._CONFIG.thirdLoginUrl +
|
||||
'?response_type=code&active_type=user&state=' +
|
||||
|
|
|
@ -26,7 +26,10 @@ const errorHandler = (error) => {
|
|||
description: data.message,
|
||||
})
|
||||
}
|
||||
if (error.response.status === 401 && !(data.result && data.result.isLogin)) {
|
||||
if (
|
||||
(error.response.status === 500 && error.response.data.message === '未找到授权信息') ||
|
||||
(error.response.status === 401 && !(data.result && data.result.isLogin))
|
||||
) {
|
||||
notification.error({
|
||||
message: '温馨提示',
|
||||
description: '登录过期,请重新登录',
|
||||
|
@ -35,13 +38,19 @@ const errorHandler = (error) => {
|
|||
if (token) {
|
||||
store.dispatch('Logout').then(() => {
|
||||
setTimeout(() => {
|
||||
// if (process.env.NODE_ENV === 'production') {
|
||||
// openThirdLogin()
|
||||
// } else {
|
||||
window.location.reload()
|
||||
// }
|
||||
if (process.env.NODE_ENV === 'production') {
|
||||
openThirdLogin()
|
||||
} else {
|
||||
window.location.reload()
|
||||
}
|
||||
}, 1500)
|
||||
})
|
||||
} else {
|
||||
if (process.env.NODE_ENV === 'production') {
|
||||
openThirdLogin()
|
||||
} else {
|
||||
window.location.reload()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
</template>
|
||||
|
||||
<script>
|
||||
import { getAction } from '@/api/manage'
|
||||
import { mapState } from 'vuex'
|
||||
|
||||
export default {
|
||||
|
@ -81,7 +82,27 @@ export default {
|
|||
userInfo: (state) => state.user.info,
|
||||
}),
|
||||
},
|
||||
created() {
|
||||
async created() {
|
||||
const searchParams = new URLSearchParams(window.location.search)
|
||||
const searchCode = searchParams.get('code')
|
||||
const localCode = window.localStorage.getItem('code')
|
||||
if (searchCode) {
|
||||
window.localStorage.setItem('code', searchCode)
|
||||
window.location.href = window.location.origin + window.location.pathname
|
||||
} else if (localCode) {
|
||||
try {
|
||||
const tokenRes = await getAction('/oauth2/thirdLogin', { code: localCode })
|
||||
storage.set(ACCESS_TOKEN, tokenRes.data.token, 7 * 24 * 60 * 60 * 1000)
|
||||
this.$store.commit('SET_TOKEN', tokenRes.data.token)
|
||||
await this.$store.dispatch('GetInfo')
|
||||
} catch (error) {
|
||||
console.log(error)
|
||||
} finally {
|
||||
window.localStorage.removeItem('code')
|
||||
}
|
||||
} else {
|
||||
this.$store.dispatch('GetInfo')
|
||||
}
|
||||
window.addEventListener('beforeunload', (e) => {
|
||||
this.openChildren.forEach((childWindow) => {
|
||||
childWindow && childWindow.close()
|
||||
|
|
Loading…
Reference in New Issue
Block a user