A minimal app demonstrating Auth0 login using the Authorization Code Flow. It consists of an Express backend and a React (Vite) frontend.
backend/ – Express API handling Auth0 login, callback, token exchange, and user info
frontend/ – React app with login/logout UI
Create a Regular Web Application in the Auth0 Dashboard and configure:
- Allowed Callback URLs:
http://localhost:3000/callback - Allowed Logout URLs:
http://localhost:5173
cd backend
cp .env.example .env # then fill in your Auth0 credentials
yarn install
yarn startRequired environment variables in backend/.env:
| Variable | Description |
|---|---|
AUTH0_DOMAIN |
Your Auth0 tenant domain |
AUTH0_CLIENT_ID |
Application client ID |
AUTH0_CLIENT_SECRET |
Application client secret |
FRONTEND_URL |
Frontend URL (default: http://localhost:5173) |
cd frontend
npm install
npm run devOpens at http://localhost:5173.
- User clicks Log in on the frontend
- Browser navigates to
backend/login, which redirects to Auth0's Universal Login - After authentication, Auth0 redirects to
backend/callbackwith an authorization code - The backend exchanges the code for tokens via Auth0's
/oauth/tokenendpoint - The access token is stored as an httpOnly cookie and the user is redirected back to the frontend
- The frontend calls
backend/me, which uses the access token to fetch user info from Auth0's/userinfoendpoint - Log out clears the cookie