RegisterLogin
DocsPricing
RegisterLogin
  • Getting Started
  • Introduction
  • Quick Start
  • SDKs
  • React
  • TypeScript
  • Next.js
  • Express
  • NestJS
  • Python
  • API Reference
  • Support and Resources
  • FAQ
  • Contact Support

AuthSafe

Product

HighlightFeatureIntegrationPricingFAQ

Company

AboutBlogContactSitemap

Developer

DashboardDocumentation

Legal

Terms & ConditionsPrivacyComplianceShippingCancellation

© 2026 AuthSafe. All rights reserved.

We value your privacy

This website uses cookies for anonymous analytics to help us improve your experience. No personal information is stored or shared. You can allow or reject analytics tracking at any time. See our Privacy Policy.

We use cookies for anonymous analytics. No personal info is stored. See our Privacy Policy.

useLogout()

A React hook that provides functionality to sign out the current user. It clears the authentication state and removes stored tokens.

Basic Usage

import { useLogout } from 'authsafe-react';

function LogoutButton() {
  const { logout } = useLogout();

  return (
    <button onClick={logout}>
      Logout
    </button>
  );
}

Return Values

PropertyTypeDescription
logout() => Promise<void>Async function to sign out the current user
isLoadingbooleanIndicates if the logout process is in progress
errorError | nullAny error that occurred during logout

Logout with Post-Logout Actions

Handle post-logout redirects or cleanup:
import { useLogout } from 'authsafe-react';
import { useNavigate } from 'react-router-dom';

function LogoutButton() {
  const { logout, isLoading } = useLogout();
  const navigate = useNavigate();

  const handleLogout = async () => {
    await logout();
    // Redirect to home page after logout
    navigate('/');
  };

  return (
    <button onClick={handleLogout} disabled={isLoading}>
      {isLoading ? 'Logging out...' : 'Logout'}
    </button>
  );
}

Complete Example

import { useLogout, useAuth } from 'authsafe-react';

function UserMenu() {
  const { user } = useAuth();
  const { logout, isLoading, error } = useLogout();

  if (error) {
    console.error('Logout error:', error);
  }

  return (
    <div>
      <p>Welcome, {user?.name}</p>
      <button onClick={logout} disabled={isLoading}>
        {isLoading ? 'Logging out...' : 'Logout'}
      </button>
    </div>
  );
}

Type Definition

interface UseLogoutReturn {
  logout: () => Promise<void>;
  isLoading: boolean;
  error: Error | null;
}

What happens when logout is called?
  • All authentication tokens are cleared from storage
  • The user session is terminated
  • Authentication state is reset
  • User is redirected to the logged-out state
Best Practices
  • Always disable the logout button when isLoading is true