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
Wrap your app with AuthProvider
Wrap your application with the
AuthProvider component and pass your Logto configuration:src/App.tsx
Add the UserCenter component
Drop the The
UserCenter component into your navbar for a ready-to-use user menu:src/components/Navbar.tsx
UserCenter component automatically shows:- Avatar, name, and sign out button when authenticated
- Sign in button when not authenticated
Customize the
UserCenter with additional pages:Create a callback route
Create a route at The
/callback and render the CallbackPage component to handle OAuth redirects:src/pages/Callback.tsx
CallbackPage handles:- OAuth callback flow
- Popup authentication flow
- Redirects after successful authentication
Route protection
Protect routes by requiring authentication with themiddleware 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
Popup sign-in (optional)
Enable popup-based sign-in for a better user experience:src/App.tsx
- Authentication happens in a popup window
- Main page doesn’t reload
- Users stay on the same page after signing in
Next steps
Server authentication
Secure your API endpoints with JWT verification
Bundler configuration
Configure Vite, Webpack, or Next.js bundlers