| 1 | "use client"; |
| 2 | |
| 3 | import { useAuth, useSignOut |
| 4 | import { useEffect, useRef |
| 5 | import { Spinner } |
| 6 | import { cn } |
| 7 | |
| 8 | export type SignOutProps |
| 9 | className?: string |
| 10 | }; |
| 11 | |
| 12 | /** Signs the current user out on mount and renders a centered spinner while the operation completes. */ |
| 13 | export function SignOut({ |
| 14 | const { authClient, |
| 15 | |
| 16 | const { mutate: |
| 17 | onError: () => |
| 18 | navigate({ |
| 19 | to: `${basePaths. |
| 20 | replace: true, |
| 21 | }); |
| 22 | }, |
| 23 | onSuccess: () => |
| 24 | navigate({ |
| 25 | to: `${basePaths. |
| 26 | replace: true, |
| 27 | }), |
| 28 | }); |
| 29 | |
| 30 | const hasSignedOut = |
| 31 | |
| 32 | useEffect(() => |
| 33 | if (hasSignedOut.current |
| 34 | hasSignedOut.current = |
| 35 | |
| 36 | signOut(); |
| 37 | }, [signOut]); |
| 38 | |
| 39 | return <Spinner className |
| 40 | } |