Within my application, I have implemented 3 different access levels.
To grant the admin access to all pages, I inserted the following code in the admin section:
else if (claims.admin) {
return next()
}
This configuration successfully allows the admin to navigate through all pages of the application.
However, a drawback arises where upon logging in as the admin, the admin remains on the login page without being redirected. My goal is for the admin to retain access to all pages while being directed to the admin.vue page upon logging in.
Below is the complete code snippet:
router.beforeEach((to, from, next) => {
firebase.auth().onAuthStateChanged(userAuth => {
if (userAuth) {
firebase.auth().currentUser.getIdTokenResult()
.then(function ({
claims
}) {
if (claims.customer) {
if (to.path !== '/customer')
return next({
path: '/customer',
})
} else if (claims.admin) {
if (to.path !== '/admin')
return next({
path: '/admin',
})
} else if (claims.driver) {
if (to.path !== '/driver')
return next({
path: '/driver',
})
}
})
})