Authentication
Manage JWT Token based Authentication.
How does it work?
Main.ts
import { fakeBackend } from '@/utils/helpers/fake-backend';
fakeBackend();router
router.beforeEach((to) => {
const auth = useAuthStore();
const routeName = String(to.name ?? '');
const authRequired = routeName.startsWith('/(main)') || to.matched.some((record) => record.meta.requiresAuth === true);
if (authRequired && !auth.user) {
auth.returnUrl = to.fullPath;
return { path: '/login' };
}
if (auth.user && to.path === '/login') {
return { path: auth.returnUrl || '/dashboard/default' };
}
});Last updated