File tree 1 file changed +6
-4
lines changed
1 file changed +6
-4
lines changed Original file line number Diff line number Diff line change @@ -28,7 +28,7 @@ interface authStore {
28
28
export const useAuthStore = create < authStore > ( ( set ) => ( {
29
29
signinError : null ,
30
30
isSigningIn : false ,
31
- signin : async ( signinMetaData , router ) => {
31
+ signin : async ( signinMetaData , router ) => {
32
32
const supabase = createClient ( )
33
33
set ( { isSigningIn : true , signinError : null } )
34
34
try {
@@ -42,8 +42,9 @@ export const useAuthStore = create<authStore>((set) => ({
42
42
}
43
43
44
44
if ( data . session ) {
45
- // Ensure we have a session before redirecting
46
- await router . push ( '/dashboard' ) ;
45
+ // For reliable redirection, reload the page instead of using router.push
46
+ // This ensures the middleware properly detects the authentication state
47
+ window . location . href = '/dashboard' ;
47
48
} else {
48
49
throw new Error ( "Unable to retrieve session after login." ) ;
49
50
}
@@ -59,7 +60,8 @@ export const useAuthStore = create<authStore>((set) => ({
59
60
const supabase = createClient ( )
60
61
try {
61
62
await supabase . auth . signOut ( ) ;
62
- router . push ( '/auth/signin' ) ;
63
+ // Use window.location for reliable redirection after logout
64
+ window . location . href = '/auth/signin' ;
63
65
} catch ( error ) {
64
66
console . error ( 'Logout error:' , error ) ;
65
67
}
You can’t perform that action at this time.
0 commit comments