A quick start SvelteKit template demonstrating user authentication and authorization using Neon RLS Authorize with WorkOS integration. This example showcases how to use WorkOS for authentication and Neon RLS Authorize for securing your database with Row Level Security (RLS).
Deploy this example to Netlify with a single click:
Important: After deploying, ensure your WorkOS Redirect URI is set to your deployment URL (e.g.,
https://your-app-name.netlify.app/callback
) in your WorkOS Application settings.
http://localhost:5173/callback
.Open your Neon Console and click "RLS Authorize" in your project's settings.
Add a new authentication provider.
Set the JWKS URL to: {YOUR_WORKOS_URL}/.well-known/jwks.json
Replace
{YOUR_WORKOS_URL}
with your WorkOS domain (e.g.,https://api.workos.com/sso/jwks/{YOUR_CLIENT_ID}
). You can find the exact format in your.env.example
asWORKOS_JWKS_URL
.
Clone the repository:
git clone https://github.com/neondatabase-labs/workos-drizzle-sveltekit-neon-rls-authorize
cd workos-drizzle-sveltekit-neon-rls-authorize
Install dependencies:
npm install
Create a .env
file based on .env.example
and fill in the necessary values:
# For the admin `neondb_owner` role.
DATABASE_URL=
# For the `authenticated`, passwordless role.
DATABASE_AUTHENTICATED_URL=
# For the `anonymous` role, passwordless role.
DATABASE_ANONYMOUS_URL=
WEBSITE_URL=http://localhost:5173 # Change to your deployment URL
# from the WorkOS dashboard
WORKOS_API_KEY=
# from the WorkOS dashboard
WORKOS_CLIENT_ID=
# format is https://api.workos.com/sso/jwks/{client_id}
WORKOS_JWKS_URL=
# run `openssl rand -base64 64` to generate a new password
WORKOS_COOKIE_PASSWORD=
Set up the database:
npm run db:generate # Generate migrations
npm run db:migrate # Run migrations
Start the development server:
npm run dev -- --open
Visit http://localhost:5173
to see the application running.
Update your WorkOS environment to production and the JWKS URL in Neon RLS Authorize accordingly.
Note: Before deploying to production, ensure you have configured the correct Redirect URI in your WorkOS Application settings to match your deployed application's URL (e.g.,
https://your-app-name.netlify.app/callback
).
Contributions are welcome! Please feel free to submit a Pull Request.