You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
OneAuth/oaweb/middleware/auth.ts

32 lines
825 B
TypeScript

3 weeks ago
/*
* auth.ts
* Copyright (C) 2024 veypi <i@veypi.com>
* 2024-11-05 10:34
* Distributed under terms of the GPL license.
*/
import oaer from '@veypi/oaer'
oaer.on('logout', () => {
let r = useRoute()
console.log(r.path)
if (r.path === now_auth && r.path !== '/') {
oaer.goto('/')
}
})
let now_auth = ''
export default defineNuxtRouteMiddleware((to, from) => {
console.log(to.path)
if (!oaer.isValid() && to.path !== '/login') {
return navigateTo('/login')
}
now_auth = to.path
// if (to.params.id === '1') {
// return abortNavigation()
// }
// 在实际应用中,你可能不会将每个路由重定向到 `/`
// 但是在重定向之前检查 `to.path` 是很重要的,否则可能会导致无限重定向循环
// if (to.path !== '/') {
// return navigateTo('/')
// }
})