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',
|
path: '/login',
|
||||||
name: 'user.login',
|
name: 'user.login',
|
||||||
component: LoginComponent,
|
component: LoginComponent,
|
||||||
|
meta: {
|
||||||
|
accessibleWithoutAuth: true,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: '/get-password-reset',
|
path: '/get-password-reset',
|
||||||
|
@ -522,9 +525,27 @@ router.resolve({
|
||||||
params: { pathMatch: ['not', 'found'] },
|
params: { pathMatch: ['not', 'found'] },
|
||||||
}).href // '/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) {
|
function canUserAccess(to) {
|
||||||
// Check if the user is already logged in and redirect them to the home page if not
|
// Check if the user is already logged in and redirect them to the home page if not
|
||||||
if (
|
if (
|
||||||
|
(to.matched.some(record => record.meta.accessibleWithoutAuth))
|
||||||
to.name !== 'user.login' &&
|
to.name !== 'user.login' &&
|
||||||
to.name !== 'user.password-reset.request' &&
|
to.name !== 'user.password-reset.request' &&
|
||||||
to.name !== 'user.password-reset.reset' &&
|
to.name !== 'user.password-reset.reset' &&
|
||||||
|
@ -537,7 +558,6 @@ function canUserAccess(to) {
|
||||||
saveLastVisited(to.name, to.params)
|
saveLastVisited(to.name, to.params)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
router.beforeEach(async (to, from) => {
|
router.beforeEach(async (to, from) => {
|
||||||
|
|
Reference in New Issue