feat: allow temporary intranet no-login mode
This commit is contained in:
@@ -50,8 +50,19 @@ const router = createRouter({
|
||||
routes,
|
||||
})
|
||||
|
||||
// 路由守卫:检查登录
|
||||
// 默认运行在内网免登录模式;需要 Casdoor 时构建时设置 VITE_AUTH_ENABLED=true。
|
||||
const authEnabled = import.meta.env.VITE_AUTH_ENABLED === 'true'
|
||||
|
||||
router.beforeEach((to, from, next) => {
|
||||
if (!authEnabled) {
|
||||
if (to.name === 'Login') {
|
||||
next({ name: 'Dashboard' })
|
||||
} else {
|
||||
next()
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
const token = localStorage.getItem('token')
|
||||
if (to.name !== 'Login' && !token) {
|
||||
next({ name: 'Login' })
|
||||
|
||||
Reference in New Issue
Block a user