Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update local development setup with Ngrok for Clerk #254

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion apps/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
"name": "api",
"private": true,
"scripts": {
"dev": "concurrently \"pnpm:next\" \"pnpm:stripe\"",
"dev": "concurrently \"pnpm:next\" \"pnpm:stripe\" \"pnpm:ngrok\"",
"next": "next dev -p 3002 --turbopack",
"build": "next build",
"start": "next start",
"analyze": "ANALYZE=true pnpm build",
"ngrok": "ngrok http --url=your-domain-name 3002",
"stripe": "stripe listen --forward-to localhost:3002/webhooks/stripe"
},
"dependencies": {
Expand Down
15 changes: 14 additions & 1 deletion docs/authentication.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,17 @@ Clerk uses webhooks to handle authentication events. These are handled in the `P

### Local Development

Currently there's no way to easily test Clerk webhooks locally, so you'll have to test them in a staging environment. This means deploying your app to a "production" state Vercel project with development environment variables e.g. `staging-api.example.com`. Then you can add this URL to your Clerk project's webhook settings.
To test webhooks locally, you can use Ngrok to expose your local server to the internet. This allows Clerk to send webhooks to your local development environment.

1. Install Ngrok by following the instructions on the [Ngrok website](https://ngrok.com/download).
2. Start your local development server and Ngrok by running the following command in the `api` app:

```sh
pnpm dev
```

This will start the Next.js development server on port 3002, the Stripe CLI to forward webhooks to your local server, and Ngrok to expose your local server to the internet.

3. Copy the forwarding URL provided by Ngrok (e.g., `https://<your-ngrok-subdomain>.ngrok.io`) and add it to your Clerk project's webhook settings.

4. Now you can test Clerk webhooks locally without needing to deploy your app to a staging environment.
6 changes: 6 additions & 0 deletions docs/setup.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ cd docs
mintlify dev
```

### Ngrok

We use Ngrok to expose your local server to the internet for testing webhooks. You can read more about that [here](/authentication#local-development).

Learn how to [install Ngrok](https://ngrok.com/download) for your operating system.

### Accounts

next-forge relies on various SaaS products. You will need to create accounts with the following services then set the API keys in your [environment variables](/env):
Expand Down