useLogOut
The useLogOut hook handles the logout mutation.
import { useLogOut } from '@archibald/auth';
const { logout, isLoading } = useLogOut(OPTIONS);
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| options | MutateOptions | Options that define the behavior of the useMutation hook used internally. |
Return value
| Property | Type | Description |
|---|---|---|
| logout | Function | Function to trigger the logout. |
| isLoading | boolean | Indicates if the logout request is in progress. |
| error | Error | null | Error object if the logout failed. |
| isDone | boolean | Returns true when the logout request finished. |
Usage Example
import { useLogOut } from '@archibald/auth';
function LogoutButton() {
const { logout, isLoading } = useLogOut();
return (
<button onClick={logout} disabled={isLoading}>
{isLoading ? 'Logging out...' : 'Log Out'}
</button>
);
}
Relates to
SessionClient: UsessessionClient.logOut()to terminate the session.useMutation: Internally uses@archibald/client'suseMutationto handle the request state.DataClient: Automatically refetches thesession-userkey after a successful logout to clear user data from the cache.