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.

Quick Start Guide

Get your application up and running with AuthSafe authentication in less than 10 minutes. This guide walks you through the essential steps to integrate secure authentication into your app.
5-10 minutes
React SDK
OAuth 2.0

Before You Begin

Before integrating AuthSafe, make sure you have:
Prerequisites
  • Node.js 16.x or higher installed
  • React 18.x or higher
  • An AuthSafe account (sign up at our dashboard)
  • A registered application with client credentials
What You'll Build
  • Login/Logout functionality
  • Protected routes and pages
  • User profile display
  • OAuth 2.0 callback handling

Step 1: Register Your Application

First, you need to register your application in the AuthSafe dashboard to get your credentials.
  1. Go to the AuthSafe Dashboard
  2. Create a new application
    • Click "Create Application"
    • Enter your application name
    • Select "Single Page Application" as the type
  3. Configure your application
    • Set your redirect URI (e.g., http://localhost:3000/callback)
    • Note your Client ID - you'll need this later
  4. Save your settings
Keep Your Client ID Safe
Your Client ID is public and safe to use in client-side code. However, never commit sensitive credentials to version control.

Step 2: Install the SDK

Install the AuthSafe React SDK using your preferred package manager:
# Using npm
npm install authsafe-react

# Using yarn
yarn add authsafe-react

# Using pnpm
pnpm add authsafe-react

Step 3: Configure the AuthProvider

Wrap your application with the AuthProvider component. This is typically done in your root layout or main App component.
// app/layout.tsx or App.tsx
import { AuthProvider } from 'authsafe-react';

export default function RootLayout({ children }) {
  return (
    <AuthProvider
      config={{
        clientId: 'your-client-id-here',
        redirectUri: 'http://localhost:3000/callback',
        scope: ['openid', 'profile', 'email'],
        env: 'production',
      }}
    >
      {children}
    </AuthProvider>
  );
}
Environment Configuration
  • Use env: 'development' for local development
  • Use env: 'production' for production deployments
  • The scope array determines what user information you can access

Step 4: Create the OAuth Callback Page

Create a callback page to handle the OAuth redirect after login.
// app/callback/page.tsx
'use client';

import { useOAuthCallback } from 'authsafe-react';

export default function CallbackPage() {
  const { isLoading, error } = useOAuthCallback();

  if (isLoading) {
    return <div>Processing login...</div>;
  }

  if (error) {
    return <div>Error: {error.message}</div>;
  }

  return <div>Login successful! Redirecting...</div>;
}

Step 5: Add Login and Logout

Now you can add login and logout functionality to your application.
'use client';

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

export default function AuthButtons() {
  const { signinRedirect, isLoading: loginLoading } = useLogin();
  const { logout, isLoading: logoutLoading } = useLogout();
  const { isAuthenticated, user } = useAuth();

  if (isAuthenticated) {
    return (
      <div>
        <p>Welcome, {user?.name || user?.email}!</p>
        <button 
          onClick={() => logout()} 
          disabled={logoutLoading}
        >
          {logoutLoading ? 'Logging out...' : 'Logout'}
        </button>
      </div>
    );
  }

  return (
    <button 
      onClick={() => signinRedirect()} 
      disabled={loginLoading}
    >
      {loginLoading ? 'Logging in...' : 'Login with AuthSafe'}
    </button>
  );
}

Step 6: Protect Routes (Optional)

Protect specific routes or pages by checking authentication status.
'use client';

import { useAuth } from 'authsafe-react';
import { useRouter } from 'next/navigation';
import { useEffect } from 'react';

export default function ProtectedPage() {
  const { isAuthenticated, isLoading } = useAuth();
  const router = useRouter();

  useEffect(() => {
    if (!isLoading && !isAuthenticated) {
      router.push('/');
    }
  }, [isAuthenticated, isLoading, router]);

  if (isLoading) {
    return <div>Loading...</div>;
  }

  if (!isAuthenticated) {
    return null;
  }

  return (
    <div>
      <h1>Protected Content</h1>
      <p>Only authenticated users can see this!</p>
    </div>
  );
}

Complete Example

Here's a complete working example showing all the pieces together:
import { AuthProvider, useLogin, useAuth, useLogout } from 'authsafe-react';

function App() {
  return (
    <AuthProvider
      config={{
        clientId: 'your-client-id',
        redirectUri: 'http://localhost:3000/callback',
        scope: ['openid', 'profile', 'email'],
        env: 'production',
      }}
    >
      <YourApp />
    </AuthProvider>
  );
}

function LoginButton() {
  const { signinRedirect, isLoading } = useLogin();

  return (
    <button onClick={() => signinRedirect()} disabled={isLoading}>
      {isLoading ? 'Logging in...' : 'Login with AuthSafe'}
    </button>
  );
}

function UserProfile() {
  const { user, isAuthenticated } = useAuth();
  const { logout } = useLogout();

  if (!isAuthenticated) {
    return <LoginButton />;
  }

  return (
    <div>
      <h2>Welcome, {user?.name || user?.email}</h2>
      <button onClick={() => logout()}>Logout</button>
    </div>
  );
}

Next Steps

Explore the React SDK

Learn about all available hooks, components, and utilities in the React SDK documentation.

View React SDK Docs →

Advanced Features

Implement popup login, silent token renewal, and custom authentication flows.

View Advanced Guides →

API Reference

Explore the complete API documentation for all endpoints and configuration options.

View API Docs →


Common Issues & Troubleshooting

Redirect URI Mismatch
If you get a "redirect_uri_mismatch" error, make sure the redirectUri in your config exactly matches what you configured in the dashboard, including the protocol (http/https), port, and path.
Authentication State Not Persisting
The SDK automatically handles token storage in localStorage. If authentication state is not persisting across page reloads, check your browser's localStorage settings and ensure it's enabled.
CORS Errors
CORS errors typically indicate a mismatch between your application's origin and the allowed origins in your AuthSafe dashboard. Make sure to add your development and production URLs to the allowed origins list.

Need Help?

If you run into any issues:
  • Check the FAQ for common questions
  • Review the full React SDK documentation
  • Contact our support team for assistance
Congratulations!

You've successfully integrated AuthSafe into your application. Your users can now securely authenticate using industry-standard OAuth 2.0 and OpenID Connect protocols.