feat(auth): enhance logout and login flow with return URL handling
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user