Redirect to an URL option in signOut() #128

Closed
opened 2026-03-13 07:34:29 -05:00 by GiteaMirror · 2 comments
Owner

Originally created by @mmikhan on GitHub (Oct 23, 2024).

Right now, signOut() function doesn't handle the redirect after signing out. It only accept {fetchOptions: {redirect: RequestRedirect}}. RequestRedirect can be either follow, error, or manual but no URL. Manually adding a redirect doesn't validate whether the sign out action was successful. So, it would be great to have a redirect to option there.

Originally created by @mmikhan on GitHub (Oct 23, 2024). Right now, `signOut()` function doesn't handle the redirect after signing out. It only accept `{fetchOptions: {redirect: RequestRedirect}}`. `RequestRedirect` can be either `follow`, `error`, or `manual` but no URL. Manually adding a redirect doesn't validate whether the sign out action was successful. So, it would be great to have a redirect to option there.
Author
Owner

@mmikhan commented on GitHub (Oct 23, 2024):

As a workaround, fetchOptions has an onSuccess() function that can be used to redirect on a successful sign out.

8899ed1877/demo/nextjs/app/dashboard/user-card.tsx (L390-L396)

@mmikhan commented on GitHub (Oct 23, 2024): As a workaround, `fetchOptions` has an `onSuccess()` function that can be used to redirect on a successful sign out. https://github.com/better-auth/better-auth/blob/8899ed18771fa221376182c014804a52e6c019d4/demo/nextjs/app/dashboard/user-card.tsx#L390-L396
Author
Owner

@RubenSmn commented on GitHub (May 28, 2025):

I also added router.refresh() after the push. After I signed out I was still able to visit pages with the browser history back button. The refresh prevents this.

    await authClient.signOut({
      fetchOptions: {
        onSuccess: () => {
          router.push(Routes.getSignIn());
          router.refresh();
        },
      },
    });
@RubenSmn commented on GitHub (May 28, 2025): I also added `router.refresh()` after the push. After I signed out I was still able to visit pages with the browser history back button. The refresh prevents this. ```ts await authClient.signOut({ fetchOptions: { onSuccess: () => { router.push(Routes.getSignIn()); router.refresh(); }, }, }); ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#128