Skip to main content

useLogOut

The useLogOut hook handles the logout mutation.

import { useLogOut } from '@archibald/auth';

const { logout, isLoading } = useLogOut(OPTIONS);

Parameters

NameTypeRequiredDescription
optionsMutateOptionsOptions that define the behavior of the useMutation hook used internally.

Return value

PropertyTypeDescription
logoutFunctionFunction to trigger the logout.
isLoadingbooleanIndicates if the logout request is in progress.
errorError | nullError object if the logout failed.
isDonebooleanReturns 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: Uses sessionClient.logOut() to terminate the session.
  • useMutation: Internally uses @archibald/client's useMutation to handle the request state.
  • DataClient: Automatically refetches the session-user key after a successful logout to clear user data from the cache.