A quick start Next.js template demonstrating secure user authentication and authorization using Neon RLS Authorize with Auth0 integration. This guide primarily uses SQL from the backend to enforce row-level security policies.
- Next.js application with TypeScript
- User authentication powered by Auth0
- Row-level security using Neon RLS Authorize
- Database migrations with Drizzle ORM
- Ready-to-deploy configuration for Vercel, Netlify, and Render
Deploy directly to your preferred hosting platform:
Important: After deployment, set
AUTH0_BASE_URL
to your deployment URL and ensure the "Callback URLs" and "Logout URLs" in your Auth0 application settings are correctly configured for your deployment URL.
- Navigate to your Auth0 dashboard and select your application.
- Under "Application URIs", configure:
- Callback URLs:
http://localhost:3000/api/auth/callback
- Logout URLs:
http://localhost:3000
- Callback URLs:
- Open your Neon Console and click "RLS Authorize" in your project's settings
- Add a new authentication provider
- Set the JWKS URL to:
https://{YOUR_AUTH0_DOMAIN}/.well-known/jwks.json
Replace
{YOUR_AUTH0_DOMAIN}
with your Auth0 domain.
-
Clone the repository:
git clone https://github.com/neondatabase-labs/auth0-nextjs-neon-rls-authorize cd auth0-nextjs-neon-rls-authorize
-
Install dependencies:
npm install
-
Create
.env
file with the following variables:# For the `neondb_owner` role. DATABASE_URL= # For the `authenticated`, passwordless role. DATABASE_AUTHENTICATED_URL= AUTH0_SECRET={ANY SECRET UNIQUE STRING} (at least 32 characters, used to encrypt the cookie - use `openssl rand -base64 32`) AUTH0_ISSUER_BASE_URL=https://{YOUR_AUTH0_DOMAIN} AUTH0_BASE_URL=http://localhost:3000/ AUTH0_CLIENT_ID={YOUR_AUTH0_CLIENT_ID} AUTH0_CLIENT_SECRET={YOUR_AUTH0_CLIENT_SECRET} AUTH0_SCOPE=openid profile read:shows AUTH0_AUDIENCE={YOUR_AUTH0_API_IDENTIFIER}
Get your Auth0 credentials from your Auth0 application settings. You can create a new API in the "APIs" section of your Auth0 dashboard to get the
AUTH0_API_IDENTIFIER
. -
Set up the database:
npm run drizzle:generate # Generate migrations npm run drizzle:migrate # Apply migrations
-
Start the development server:
npm run dev
-
Visit
http://localhost:3000
to see the application running
Contributions are welcome! Please feel free to submit a Pull Request.