feat(auth): enhance logout and login flow with return URL handling

This commit is contained in:
2025-04-25 14:41:58 -04:00
parent 2c09be4465
commit e394c346ae
5 changed files with 53 additions and 11 deletions

View File

@@ -94,6 +94,7 @@ const routes = [
name: 'login',
component: LoginView,
meta: { notAuthenticated: true },
props: (route) => ({ returnUrl: route.query.returnUrl || '/landing' })
},
{
path: '/profile',
@@ -119,11 +120,20 @@ router.beforeEach((to, from, next) => {
const authStore = useAuthStore();
if (to.matched.some((record) => record.meta.requiresAuth)) {
if (!authStore.isAuthenticated) next({ name: 'login' });
if (!authStore.isAuthenticated) {
next({
name: 'login',
query: { returnUrl: to.fullPath }
});
} else {
next();
}
} else if (to.matched.some((record) => record.meta.notAuthenticated)) {
if (authStore.isAuthenticated) next({ name: 'landing' });
else next();
} else {
next();
}
next();
});
export default router;