I have the following code snipped from my middleware/auth.js that redirects users to login page if the users are unauthenticated.
export default function ({ store, redirect }) {
if (!store.state.admin.isAdmin) {
redirect('/auth/login')
}
}
Now I want to forbid authenticated users visiting login page and redirect to ('/manage/dashboard') when they hit the login url.
I have used the following approach in my login view:
mounted () {
if (localStorage.getItem('token') && localStorage.getItem('userId')) {
this.$router.replace({ path: '/admin/dashboard' })
}
}
This works but the execution is too slow and user can see login page for few seconds.
What is the efficient way to achieve the redirect ?