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

@@ -72,7 +72,7 @@ export const useAuthStore = defineStore(
// Clear any other auth-related data if needed
}
async function logout() {
async function logout(redirectTo = '/landing') {
try {
// Optionally call logout endpoint if you have one
// await clientApi.post('api/users/logout');
@@ -80,7 +80,7 @@ export const useAuthStore = defineStore(
console.error('Logout failed:', error);
} finally {
cleanTokens();
await router.push('/');
await router.push(redirectTo);
}
}
@@ -201,8 +201,15 @@ export const useAuthStore = defineStore(
// Only clear tokens and session storage after a failed refresh attempt
cleanTokens();
// Force a redirect to the login page
await router.push('/login');
// Get the current route to use as returnUrl
const currentRoute = router.currentRoute.value;
const returnUrl = currentRoute.fullPath;
// Force a redirect to the login page with returnUrl
await router.push({
name: 'login',
query: { returnUrl }
});
throw error;
}