This is a Next.js project bootstrapped with create-next-app.
First, run the development server:
npm run dev
# or
yarn dev
# or
pnpm dev
# or
bun devOpen http://localhost:3000 with your browser to see the result.
You can start editing the page by modifying app/page.tsx. The page auto-updates as you edit the file.
This project uses next/font to automatically optimize and load Geist, a new font family for Vercel.
This project uses Auth0 for authentication. To set it up:
- Create an Auth0 account and application at auth0.com
- Add the following environment variables to your
.env.localfile:
AUTH0_SECRET='use [openssl rand -hex 32] to generate'
AUTH0_BASE_URL='http://localhost:3000'
AUTH0_ISSUER_BASE_URL='https://YOUR_AUTH0_DOMAIN'
AUTH0_CLIENT_ID='YOUR_CLIENT_ID'
AUTH0_CLIENT_SECRET='YOUR_CLIENT_SECRET'
AUTH0_AUDIENCE='YOUR_API_AUDIENCE' # Optional, only if using API- Configure your Auth0 application:
- Allowed Callback URLs:
http://localhost:3000/api/auth/callback - Allowed Logout URLs:
http://localhost:3000 - Allowed Web Origins:
http://localhost:3000
- Allowed Callback URLs:
Server Components:
import { requireAuth, checkAuth, getCurrentUser } from '@/lib/auth0';
// Require authentication (redirects if not logged in)
export default async function ProtectedPage() {
const session = await requireAuth();
return <div>Welcome {session.user.name}</div>;
}
// Check authentication without redirecting
export default async function Page() {
const session = await checkAuth();
if (session) {
return <div>Logged in as {session.user.name}</div>;
}
return <div>Not logged in</div>;
}Client Components:
'use client';
import { useUser } from '@auth0/nextjs-auth0/client';
export default function ClientComponent() {
const { user, error, isLoading } = useUser();
// Use user, error, isLoading as needed
}To learn more about Next.js, take a look at the following resources:
- Next.js Documentation - learn about Next.js features and API.
- Learn Next.js - an interactive Next.js tutorial.
- Auth0 Next.js SDK - Auth0 integration guide.
You can check out the Next.js GitHub repository - your feedback and contributions are welcome!
The easiest way to deploy your Next.js app is to use the Vercel Platform from the creators of Next.js.
Check out our Next.js deployment documentation for more details.