SignOut doesn't redirect

Why does this not redirect IMMEDIATELY <DropdownMenuItem onClick={async () => { await authClient.signOut(); }} > <LogOut /> Log out </DropdownMenuItem>
2 Replies
arnez
arnezOP4w ago
@Better Auth @Better Auth Why does this not redirect IMMEDIATELY <DropdownMenuItem onClick={async () => { await authClient.signOut(); }} > <LogOut /> Log out </DropdownMenuItem>
Better Auth
Better Auth4w ago
The behavior you're experiencing is due to the asynchronous nature of the sign-out process. By default, calling authClient.signOut() won’t automatically trigger a page redirect—you need to explicitly instruct it to redirect after the sign-out is completed. For example, you can pass a fetchOptions object with an onSuccess handler that performs the redirect:
await authClient.signOut({
fetchOptions: {
onSuccess: () => {
router.push("/login");
},
},
});
await authClient.signOut({
fetchOptions: {
onSuccess: () => {
router.push("/login");
},
},
});
This ensures that the redirect happens only after the sign-out process finishes, which might not feel "immediate" if the network call or session cleanup takes a moment [1][10]. Sources: [1] Basic Usage | Better Auth [10] Redirect after SignOut
Basic Usage | Better Auth
Getting started with Better Auth
GitHub
Redirect after SignOut · Issue #798 · better-auth/better-auth
After Sign Out, I want to redirect, so I think this can be like that: Manually signOut({ redirectUri: &quot;/login&quot; }) or by config createAuthClient({ baseURL: import.meta.env.VITE_API_URL, si...

Did you find this page helpful?