Skip to main content
This example demonstrates how to build a complete React SPA with authentication using logto-authkit. It includes user sign-in, protected routes, and user profile management.

Complete Example

1

Install Dependencies

First, install logto-authkit and its peer dependencies:
2

Configure Logto Provider

Wrap your app with the AuthProvider to enable authentication throughout your application:
App.tsx
3

Create Home Page

Build a landing page with sign-in functionality:
pages/Home.tsx
4

Create Protected Dashboard

Build a protected dashboard page that requires authentication:
pages/Dashboard.tsx
5

Create Callback and Sign-In Pages

Add the required authentication pages:

Features Demonstrated

This example showcases:
  • Authentication Provider: Global auth state management
  • Popup Sign-In: Optional popup-based authentication flow
  • User Center Component: Pre-built user menu with avatar and sign-out
  • Protected Routes: Automatic redirection for unauthenticated users
  • Loading States: Proper handling of authentication loading states
  • User Profile Display: Accessing and displaying user information

Running the Example

Visit http://localhost:3000 to see the app in action.

Next Steps

Protected Routes

Learn advanced patterns for protecting routes

Next.js Example

See how to use logto-authkit with Next.js