Skip to main content

Quick start

This guide will help you set up logto-authkit authentication in your React application in just a few steps.

Prerequisites

Before you begin, make sure you have:
  • A Logto account and application configured
  • Your Logto endpoint URL and app ID
  • logto-authkit installed in your project
Don’t have a Logto account? Sign up for free and create your first application.

Setup steps

1

Wrap your app with AuthProvider

Wrap your application with the AuthProvider component and pass your Logto configuration:
src/App.tsx
For single-page applications, pass a customNavigate function to integrate with your router:
2

Add the UserCenter component

Drop the UserCenter component into your navbar for a ready-to-use user menu:
src/components/Navbar.tsx
The UserCenter component automatically shows:
  • Avatar, name, and sign out button when authenticated
  • Sign in button when not authenticated
Customize the UserCenter with additional pages:
3

Create a callback route

Create a route at /callback and render the CallbackPage component to handle OAuth redirects:
src/pages/Callback.tsx
The CallbackPage handles:
  • OAuth callback flow
  • Popup authentication flow
  • Redirects after successful authentication
Customize the callback experience with optional props:
4

Use the useAuth hook

Access user data and authentication actions anywhere in your app with the useAuth hook:
src/components/Dashboard.tsx

Route protection

Protect routes by requiring authentication with the middleware option:
src/pages/ProtectedPage.tsx

Guest mode

Allow anonymous users to access your app with guest mode:
src/pages/PublicPage.tsx

Refresh authentication

Manually refresh the authentication state when needed:
src/components/RefreshButton.tsx
Enable popup-based sign-in for a better user experience:
src/App.tsx
With popup sign-in enabled:
  • Authentication happens in a popup window
  • Main page doesn’t reload
  • Users stay on the same page after signing in
Popup sign-in requires a /signin route. Make sure to create one if using this feature.

Next steps

Server authentication

Secure your API endpoints with JWT verification

Bundler configuration

Configure Vite, Webpack, or Next.js bundlers