refactor: 增加环境判定,触发oneid登录
This commit is contained in:
parent
eab54b9320
commit
d5a1a8edcd
Binary file not shown.
|
@ -20,6 +20,20 @@ router.beforeEach(async(to, from, next) => {
|
|||
// determine whether the user has logged in
|
||||
const hasToken = getToken()
|
||||
|
||||
// 检查当前环境
|
||||
const isDevelopment = process.env.NODE_ENV === 'development'
|
||||
const isProduction = process.env.NODE_ENV === 'production'
|
||||
|
||||
// 根据环境启用或禁用某些代码
|
||||
// 开发环境不启用ONEID
|
||||
if (isDevelopment) {
|
||||
console.log('开发环境,启用某些代码')
|
||||
// 启用某些代码
|
||||
} else if (isProduction) {
|
||||
console.log('生产环境,禁用某些代码')
|
||||
// 禁用某些代码
|
||||
}
|
||||
|
||||
if (hasToken) {
|
||||
if (to.path === '/login' || to.path === '/callback') {
|
||||
// if is logged in, redirect to the home page
|
||||
|
@ -39,12 +53,15 @@ router.beforeEach(async(to, from, next) => {
|
|||
// remove token and go to login page to re-login
|
||||
await store.dispatch('user/resetToken')
|
||||
Message.error(error || 'Has Error')
|
||||
// next(`/login?redirect=${to.path}`)
|
||||
// NProgress.done()
|
||||
if (isDevelopment) {
|
||||
next(`/login?redirect=${to.path}`)
|
||||
NProgress.done()
|
||||
} else {
|
||||
window.location.href = ''
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
/* has no token*/
|
||||
if (whiteList.indexOf(to.path) !== -1) {
|
||||
|
@ -52,9 +69,12 @@ router.beforeEach(async(to, from, next) => {
|
|||
next()
|
||||
} else {
|
||||
// other pages that do not have permission to access are redirected to the login page.
|
||||
// next(`/login?redirect=${to.path}`)
|
||||
if (isDevelopment) {
|
||||
next(`/login?redirect=${to.path}`)
|
||||
} else {
|
||||
window.location.href = 'https://api.oneid.siemens.com.cn/api/bff/v1.2/developer/ciam/oauth/authorize?client_id=1b867769c8cb221fb7fdb0f8beba6138TwXkI4mX8um&response_type=code&redirect_uri=http://csdc.siemens.com.cn:8001/callback&scope=openid%20phone'
|
||||
// window.location.href = 'https://api.oneid.siemens.com.cn/api/bff/v1.2/developer/ciam/oauth/authorize?client_id=1b867769c8cb221fb7fdb0f8beba6138TwXkI4mX8um&response_type=code&redirect_uri=http://localhost:9528/callback&scope=openid%20phone'
|
||||
}
|
||||
NProgress.done()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue