useLogout Reference
useLogout
is a React hook that facilitates logout from your Faust app.
API
The useLogout
exports, defined as a TypeScript type:
type UseLogout = {
loading: boolean;
error: Response | undefined;
logout: (redirectUrl?: string) => void;
};
Usage
Below is an example of displaying a logout button, and upon successful logout, redirecting the user back to the homepage:
import { useLogout } from '@faustwp/core';
export function AuthenticatedView() {
const { logout } = useLogout();
return (
<>
<button onClick={() => logout('/')}>Logout</button>
</>
);
}