This sample showcases how to seamlessly add authentication and user management to your Next.js app using Frontegg’s hosted or embedded login methods.
- Redirect users to Frontegg’s hosted or embedded login
- Enable a fully integrated self-service portal
- Manage and track user authentication state
- Access and display user profile details
- Handle account state and data with ease
- Implement seamless account switching functionality
The project follows the Next.js App Router structure:
├── src/
│ ├── app/
│ │ ├── layout.tsx # Root layout with Frontegg provider
│ │ ├── page.tsx # Home page
│ │ └── account/ # Protected account route
│ ├── components/ # Reusable components
├── public/ # Static assets
If you don’t have a Frontegg account or prefer to use the sandbox credentials, feel free to skip to step 3.
If you're using your own credentials, follow the guidelines below.
- Go to Frontegg Portal
- Get your application ID from [ENVIRONMENT] → Applications
- Get your Frontegg domain from the Frontegg Portal → [ENVIRONMENT] → Keys & domains
- This sample runs on
http://localhost:3000. If your application uses a different port, make sure to addhttp://localhost:3000under → [ENVIRONMENT] → Authentication → Login method → Redirect URLs - This sample runs on
http://localhost:3000. You may need to addhttp://localhost:3000under → [ENVIRONMENT] → Keys & domains → Allowed origins
Update the .env.local file in the root directory with your Frontegg credentials. Then, choose your preferred login mode by setting FRONTEGG_HOSTED_LOGIN to false for embedded login. By default, the Frontegg sandbox environment runs in hosted mode.
FRONTEGG_BASE_URL=<YOUR_BASE_URL>
FRONTEGG_CLIENT_ID=<YOUR_CLIENT_ID>
FRONTEGG_APP_ID=<YOUR_APP_ID>
FRONTEGG_ENCRYPTION_PASSWORD=<YOUR_ENCRYPTION_PASSWORD>
FRONTEGG_HOSTED_LOGIN=<true|false>Run the following command:
git clone <repo>Run the following command:
npm installnpm run devThe app will be available at http://localhost:3000.

