feat: add auth meta check
continuous-integration/drone/pr Build is failing
Details
continuous-integration/drone/pr Build is failing
Details
This commit is contained in:
parent
89ff5ebee1
commit
0c7df1a927
|
@ -97,6 +97,9 @@ const router = createRouter({
|
|||
path: '/login',
|
||||
name: 'user.login',
|
||||
component: LoginComponent,
|
||||
meta: {
|
||||
accessibleWithoutAuth: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
path: '/get-password-reset',
|
||||
|
@ -522,9 +525,27 @@ router.resolve({
|
|||
params: { pathMatch: ['not', 'found'] },
|
||||
}).href // '/not/found'
|
||||
|
||||
|
||||
router.beforeEach((to) => {
|
||||
if (
|
||||
to.matched.some(record => record.meta.requiresAuth) &&
|
||||
// this route requires auth, check if logged in
|
||||
// if not, redirect to login page.
|
||||
!auth.loggedIn()
|
||||
) {
|
||||
return {
|
||||
path: '/login',
|
||||
query: { redirect: to.fullPath },
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
|
||||
function canUserAccess(to) {
|
||||
// Check if the user is already logged in and redirect them to the home page if not
|
||||
if (
|
||||
(to.matched.some(record => record.meta.accessibleWithoutAuth))
|
||||
to.name !== 'user.login' &&
|
||||
to.name !== 'user.password-reset.request' &&
|
||||
to.name !== 'user.password-reset.reset' &&
|
||||
|
@ -537,7 +558,6 @@ function canUserAccess(to) {
|
|||
saveLastVisited(to.name, to.params)
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
router.beforeEach(async (to, from) => {
|
||||
|
|
Reference in New Issue