A demo showcasing the integration of Supertokens for authentication and Neon Authorize for secure backend data access with Drizzle ORM in a NestJS and SolidJS application. This example demonstrates how to use Neon Authorize to enforce row-level security policies when querying your Neon database from the backend.
- NestJS backend for API development
- SolidJS frontend for a reactive user interface
- User authentication powered by Supertokens
- Row-level security using Neon Authorize
- Database interactions with Drizzle ORM
- Neon account with a new project
- Supertokens account
- Node.js installed locally
Important: This setup uses
localtunnel
to expose your local backend API for Neon Authorize configuration. Be aware that your backend will be publicly accessible as long as the tunnel is active. Remember to shut down the tunnel when you are finished.
- Sign up or log in to your Supertokens dashboard.
- Create a new project.
- Obtain your Core URI and API Key from the Supertokens dashboard.
-
Clone the repository:
git clone https://github.com/neondatabase-labs/supertokens-nestjs-solidjs-drizzle-neon-authorize cd supertokens-nestjs-solidjs-drizzle-neon-authorize
-
Install dependencies for the frontend, backend and localtunnel:
npm i && cd backend && npm i && cd ../frontend && npm i && cd ..
-
Create
.env
file in thebackend
directory with the following variables:cp backend/.env.example backend/.env
SUPERTOKENS_URI=<YOUR_SUPERTOKENS_CORE_URI> SUPERTOKENS_API_KEY=<YOUR_SUPERTOKENS_CORE_API_KEY> DATABASE_URL="" # Leave this empty for now DATABASE_AUTHENTICATED_URL="" # Leave this empty for now
-
Start the services:
npm run start
This command will start the frontend, backend, and the
localtunnel
service. -
Copy JWKS URL
- Once the
npm run start
command is running, alocaltunnel
URL will be generated and displayed in your terminal, along with the Supertokens JWKS URL. - Copy this JWKS URL.
- Return to the "Authorize" section in your Neon Console.
- Paste the copied JWKS URL into the "JWKS URL" field when adding a new authentication provider
- Follow the steps in the UI to setup the roles for Neon Authorize. You should ignore the schema related steps if you're following this guide.
- Note down the connection strings for both the
neondb_owner
role and theauthenticated, passwordless
role. You'll need both. Theneondb_owner
role has full privileges and is used for migrations, while theauthenticated
role will be used by the application and will have its access restricted by RLS.
- Once the
-
Stop the services by pressing
Ctrl + C
in the terminal. -
Update the
.env
file in thebackend
directory to include the connection strings:SUPERTOKENS_URI=<YOUR_SUPERTOKENS_CORE_URI> SUPERTOKENS_API_KEY=<YOUR_SUPERTOKENS_CORE_API_KEY> DATABASE_URL=<YOUR_NEON_DATABASE_URL_WITH_PASSWORD> DATABASE_AUTHENTICATED_URL=<YOUR_NEON_DATABASE_AUTHENTICATED_URL>
-
Apply Database Migrations:
cd backend npm run drizzle:migrate cd ..
-
Start the services again
npm run start
This command will start the frontend, backend, and the
localtunnel
service. -
Open your browser to
http://localhost:3000
to see the application running.
Note: Before deploying to production, ensure you transition your Supertokens project from development to live in the Supertokens dashboard. This will involve setting up the required DNS records for your domain. Update your environment variables in both the frontend and backend with your production Supertokens configuration.
Contributions are welcome! Please feel free to submit a Pull Request.