signOut
Signs the user out in the UI. Clears the stored token and user, then tells every useSession to re-render.
Usage
app/components/logout-button.tsx
import { Button } from "antd";
import { useNavigate } from "react-router-dom";
import { signOut } from "app/hooks";
export function LogoutButton() {
const nav = useNavigate();
return <Button onClick={() => { signOut(); nav("/login"); }}>Sign out</Button>;
}Signature
app/hooks.ts
function signOut(): void;Parameters
None.
Returns
Nothing. After the call:
- calls through
useApiClient()anduseApi()no longer send anAuthorizationheader; - getUser returns
null; - every component using useSession re-renders with
userset tonull.
signOut doesn’t navigate. Call nav("/login") yourself if you need to.
Examples
The API answers 401 when the session has expired or the account is locked. Sign out and go to the sign-in page:
app/components/api-error.tsx
import { signOut } from "app/hooks";
export function handleApiError(e: any, message: { error: (s: string) => void }, toLogin: () => void) {
if (e?.response?.status === 401) { signOut(); toLogin(); return; }
message.error(e?.response?.data?.message ?? "Something went wrong");
}Next steps
- signIn, signInWith: store the token and user after sign-in.
- Sign-in and permissions: roles in
app/auth.tsand a handler’saccess.
Last updated