javascript
javascript copied to clipboard
Webhook Not Triggering on Clerk OAuth User Creation
Preliminary Checks
-
[X] I have reviewed the documentation: https://clerk.com/docs
-
[X] I have searched for existing issues: https://github.com/clerk/javascript/issues
-
[X] I have not already reached out to Clerk support via email or Discord (if you have, no need to open an issue here)
-
[X] This issue is not a question, general help request, or anything other than a bug report directly related to Clerk. Please ask questions in our Discord community: https://clerk.com/discord.
Reproduction
https://github.com/AKRAM-2002/calisthenics-pro-lp
Publishable key
pk_test_ZGVjaWRp
Description
I'm using Clerk for user authentication in my application, and I have set up a webhook to capture user creation events (user.created). The purpose of this webhook is to persist user data in a MongoDB database. However, the webhook is not being triggered when a user signs up with a Google OAuth account.
Despite using ngrok to expose my backend server (running on port 5000), I am not seeing any logs from the webhook, and Clerk does not seem to be calling the webhook endpoint.
Steps to Reproduce:
- Set up a webhook handler on my Express server (running on port 5000)
- I used ngrok to expose the server running on port 5000(ngrok http 5000)
- updated the webhook URL in the Clerk dashboard
- test: Signed up a new user using Google OAuth in the Clerk frontend
Result:
-
Clerk not triggering the webhook for OAuth-based signups or missing some configuration on my end.
-
The webhook endpoint does not appear to be triggered at all. No logs are produced by the server, and no entries are saved to the database
Environment
Express server running locally on port 5000
Clerk integration with OAuth Google login
Webhook configured with ngrok URL
Hi.
Same here, have you found solution?
Hi y'all, are you seeing the expected user.created event in the Clerk Dashboard webhook logs? https://dashboard.clerk.com/last-active?path=webhooks
Hi @AKRAM-2002
Did you find a solution? I'm currently experiencing a similar issue, the webhook keeps failing on the clerk dashboard, but i can't see it hit my endpoint in my vercel logs. would appreciate any help thanks.
Hi y'all, are you seeing the expected
user.createdevent in the Clerk Dashboard webhook logs? https://dashboard.clerk.com/last-active?path=webhooks
Hi, yes i can but it keeps failing and i can't see it hit my domian-name/api/webhooks/clerk endpoint in my vercel log
For me it just needed some time to work
Has there been any resolution for this issue? I can't get the webhook to trigger when using Google OAuth to sign up, but it does trigger when using the regular sign up form.
Has there been any resolution for this issue? I can't get the webhook to trigger when using Google OAuth to sign up, but it does trigger when using the regular sign up form.
@psmak4 If you go to the Users tab in the Clerk dashboard, does it display the user tied to your Google OAuth? The webhook for user events will only trigger when the user falls under 1 of the 3. created, updated or deleted and won't trigger for sign in with an existing clerk user.
Yes, it's on sign up (user created) with Google OAuth. Turns out the event did trigger, but it was hours later. Is there a reason for the delay compared to when a user signs up using the regular form?
Currently facing the same issue. The webhook is not triggering upon user creation, not mattering if through Google OAuth or through Email+Password
The error from yesterday was confirmed and handled.
Hi! I've encountered the same issue as @Jeandcc. I've followed your docs, tried testing it locally with an ngrok domain forwarding port 3000, but failed, no matter how many times and different ways I try doing each different step of the process.
Here is my code:
app/api/webhooks/clerk/route.ts:
import { verifyWebhook } from '@clerk/nextjs/webhooks'
import { NextRequest } from 'next/server'
export async function POST(req: NextRequest) {
try {
const evt = await verifyWebhook(req)
// Do something with payload
// For this guide, log payload to console
const { id } = evt.data
const eventType = evt.type
console.log(`Received webhook with ID ${id} and event type of ${eventType}`)
console.log('Webhook payload:', evt.data)
return new Response('Webhook received', { status: 200 })
} catch (err) {
console.error('Error verifying webhook:', err)
return new Response('Error verifying webhook', { status: 400 })
}
}
middleware.ts:
import { clerkMiddleware } from '@clerk/nextjs/server'
// This Middleware does not protect any routes by default.
// See https://clerk.com/docs/references/nextjs/clerk-middleware for more information about configuring your Middleware
export default clerkMiddleware()
export const config = {
matcher: [
// Skip Next.js internals and all static files, unless found in search params
'/((?!_next|[^?]*\\.(?:html?|css|js(?!on)|jpe?g|webp|png|gif|svg|ttf|woff2?|ico|csv|docx?|xlsx?|zip|webmanifest)).*)',
// Always run for API routes
'/(api|trpc)(.*)',
],
}
.env.example: (Formatted with correct signing webhook secret from specific endpoint)
#### AUTHENTICATION PROVIDER ####
# Clerk Sign-in & Sign-up
### https://dashboard.clerk.com/apps/ - then into your app -> configure -> API keys
# These are the keys for development. When going to production, new keys should be generated
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=pk_test_c3VwcmVtZS1xdWFpbC0yOC5jbGVyay5hY2NvdW50cy5kZXYk
CLERK_SECRET_KEY=sk_test_...longpassword
CLERK_WEBHOOK_SIGNING_SECRET=wh_sec_signing_key_foundinyour_webhooks_clerk_section
I obtain this error:
Webhook verification failed: Error: @clerk/backend: Missing webhook signing secret. Set the CLERK_WEBHOOK_SIGNING_SECRET environment variable with the webhook secret from the Clerk Dashboard.
at Object.throw (webpack-internal:///(rsc)/./node_modules/.pnpm/@[email protected][email protected][email protected]_843bd1a73102fc369e00b1d3906479c9/node_modules/@clerk/shared/dist/chunk-3JHIKPLN.mjs:220:13)
at verifyWebhook (webpack-internal:///(rsc)/./node_modules/.pnpm/@[email protected][email protected][email protected]_cc04d19769b11fbb86d9db0da5fb312f/node_modules/@clerk/backend/dist/webhooks.mjs:23:79)
at POST (webpack-internal:///(rsc)/./app/api/webhooks/clerk/route.ts:26:90)
at /Users/anibalguerrerohernandez/Desktop/Developer/voice-agent-frontend/node_modules/.pnpm/[email protected][email protected][email protected]_bcf6a312fb11659b6e228704565bab3a/node_modules/next/dist/compiled/next-server/app-route.runtime.dev.js:6:51442
at /Users/anibalguerrerohernandez/Desktop/Developer/voice-agent-frontend/node_modules/.pnpm/[email protected][email protected][email protected]_bcf6a312fb11659b6e228704565bab3a/node_modules/next/dist/server/lib/trace/tracer.js:159:36
at NoopContextManager.with (/Users/anibalguerrerohernandez/Desktop/Developer/voice-agent-frontend/node_modules/.pnpm/[email protected][email protected][email protected]_bcf6a312fb11659b6e228704565bab3a/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:7062)
at ContextAPI.with (/Users/anibalguerrerohernandez/Desktop/Developer/voice-agent-frontend/node_modules/.pnpm/[email protected][email protected][email protected]_bcf6a312fb11659b6e228704565bab3a/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:518)
at NoopTracer.startActiveSpan (/Users/anibalguerrerohernandez/Desktop/Developer/voice-agent-frontend/node_modules/.pnpm/[email protected][email protected][email protected]_bcf6a312fb11659b6e228704565bab3a/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:18093)
at ProxyTracer.startActiveSpan (/Users/anibalguerrerohernandez/Desktop/Developer/voice-agent-frontend/node_modules/.pnpm/[email protected][email protected][email protected]_bcf6a312fb11659b6e228704565bab3a/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:18854)
at /Users/anibalguerrerohernandez/Desktop/Developer/voice-agent-frontend/node_modules/.pnpm/[email protected][email protected][email protected]_bcf6a312fb11659b6e228704565bab3a/node_modules/next/dist/server/lib/trace/tracer.js:141:103
at NoopContextManager.with (/Users/anibalguerrerohernandez/Desktop/Developer/voice-agent-frontend/node_modules/.pnpm/[email protected][email protected][email protected]_bcf6a312fb11659b6e228704565bab3a/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:7062)
at ContextAPI.with (/Users/anibalguerrerohernandez/Desktop/Developer/voice-agent-frontend/node_modules/.pnpm/[email protected][email protected][email protected]_bcf6a312fb11659b6e228704565bab3a/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:518)
at NextTracerImpl.trace (/Users/anibalguerrerohernandez/Desktop/Developer/voice-agent-frontend/node_modules/.pnpm/[email protected][email protected][email protected]_bcf6a312fb11659b6e228704565bab3a/node_modules/next/dist/server/lib/trace/tracer.js:141:28)
at /Users/anibalguerrerohernandez/Desktop/Developer/voice-agent-frontend/node_modules/.pnpm/[email protected][email protected][email protected]_bcf6a312fb11659b6e228704565bab3a/node_modules/next/dist/compiled/next-server/app-route.runtime.dev.js:6:44183
at AsyncLocalStorage.run (node:internal/async_local_storage/async_hooks:91:14)
at Object.wrap (/Users/anibalguerrerohernandez/Desktop/Developer/voice-agent-frontend/node_modules/.pnpm/[email protected][email protected][email protected]_bcf6a312fb11659b6e228704565bab3a/node_modules/next/dist/compiled/next-server/app-route.runtime.dev.js:6:37078)
at /Users/anibalguerrerohernandez/Desktop/Developer/voice-agent-frontend/node_modules/.pnpm/[email protected][email protected][email protected]_bcf6a312fb11659b6e228704565bab3a/node_modules/next/dist/compiled/next-server/app-route.runtime.dev.js:6:43290
at AsyncLocalStorage.run (node:internal/async_local_storage/async_hooks:91:14)
at Object.wrap (/Users/anibalguerrerohernandez/Desktop/Developer/voice-agent-frontend/node_modules/.pnpm/[email protected][email protected][email protected]_bcf6a312fb11659b6e228704565bab3a/node_modules/next/dist/compiled/next-server/app-route.runtime.dev.js:6:35404)
at /Users/anibalguerrerohernandez/Desktop/Developer/voice-agent-frontend/node_modules/.pnpm/[email protected][email protected][email protected]_bcf6a312fb11659b6e228704565bab3a/node_modules/next/dist/compiled/next-server/app-route.runtime.dev.js:6:43252
at AsyncLocalStorage.run (node:internal/async_local_storage/async_hooks:91:14)
at e_.execute (/Users/anibalguerrerohernandez/Desktop/Developer/voice-agent-frontend/node_modules/.pnpm/[email protected][email protected][email protected]_bcf6a312fb11659b6e228704565bab3a/node_modules/next/dist/compiled/next-server/app-route.runtime.dev.js:6:42699)
at e_.handle (/Users/anibalguerrerohernandez/Desktop/Developer/voice-agent-frontend/node_modules/.pnpm/[email protected][email protected][email protected]_bcf6a312fb11659b6e228704565bab3a/node_modules/next/dist/compiled/next-server/app-route.runtime.dev.js:6:52781)
at doRender (/Users/anibalguerrerohernandez/Desktop/Developer/voice-agent-frontend/node_modules/.pnpm/[email protected][email protected][email protected]_bcf6a312fb11659b6e228704565bab3a/node_modules/next/dist/server/base-server.js:1379:60)
at responseGenerator (/Users/anibalguerrerohernandez/Desktop/Developer/voice-agent-frontend/node_modules/.pnpm/[email protected][email protected][email protected]_bcf6a312fb11659b6e228704565bab3a/node_modules/next/dist/server/base-server.js:1605:34)
at ResponseCache.get (/Users/anibalguerrerohernandez/Desktop/Developer/voice-agent-frontend/node_modules/.pnpm/[email protected][email protected][email protected]_bcf6a312fb11659b6e228704565bab3a/node_modules/next/dist/server/response-cache/index.js:49:26)
at DevServer.renderToResponseWithComponentsImpl (/Users/anibalguerrerohernandez/Desktop/Developer/voice-agent-frontend/node_modules/.pnpm/[email protected][email protected][email protected]_bcf6a312fb11659b6e228704565bab3a/node_modules/next/dist/server/base-server.js:1618:53)
at /Users/anibalguerrerohernandez/Desktop/Developer/voice-agent-frontend/node_modules/.pnpm/[email protected][email protected][email protected]_bcf6a312fb11659b6e228704565bab3a/node_modules/next/dist/server/base-server.js:984:121
at NextTracerImpl.trace (/Users/anibalguerrerohernandez/Desktop/Developer/voice-agent-frontend/node_modules/.pnpm/[email protected][email protected][email protected]_bcf6a312fb11659b6e228704565bab3a/node_modules/next/dist/server/lib/trace/tracer.js:124:20)
at DevServer.renderToResponseWithComponents (/Users/anibalguerrerohernandez/Desktop/Developer/voice-agent-frontend/node_modules/.pnpm/[email protected][email protected][email protected]_bcf6a312fb11659b6e228704565bab3a/node_modules/next/dist/server/base-server.js:984:41)
at DevServer.renderPageComponent (/Users/anibalguerrerohernandez/Desktop/Developer/voice-agent-frontend/node_modules/.pnpm/[email protected][email protected][email protected]_bcf6a312fb11659b6e228704565bab3a/node_modules/next/dist/server/base-server.js:1931:35)
at async DevServer.renderToResponseImpl (/Users/anibalguerrerohernandez/Desktop/Developer/voice-agent-frontend/node_modules/.pnpm/[email protected][email protected][email protected]_bcf6a312fb11659b6e228704565bab3a/node_modules/next/dist/server/base-server.js:1969:32)
at async DevServer.pipeImpl (/Users/anibalguerrerohernandez/Desktop/Developer/voice-agent-frontend/node_modules/.pnpm/[email protected][email protected][email protected]_bcf6a312fb11659b6e228704565bab3a/node_modules/next/dist/server/base-server.js:902:25)
at async NextNodeServer.handleCatchallRenderRequest (/Users/anibalguerrerohernandez/Desktop/Developer/voice-agent-frontend/node_modules/.pnpm/[email protected][email protected][email protected]_bcf6a312fb11659b6e228704565bab3a/node_modules/next/dist/server/next-server.js:273:17)
at async DevServer.handleRequestImpl (/Users/anibalguerrerohernandez/Desktop/Developer/voice-agent-frontend/node_modules/.pnpm/[email protected][email protected][email protected]_bcf6a312fb11659b6e228704565bab3a/node_modules/next/dist/server/base-server.js:798:17)
at async /Users/anibalguerrerohernandez/Desktop/Developer/voice-agent-frontend/node_modules/.pnpm/[email protected][email protected][email protected]_bcf6a312fb11659b6e228704565bab3a/node_modules/next/dist/server/dev/next-dev-server.js:339:20
at async Span.traceAsyncFn (/Users/anibalguerrerohernandez/Desktop/Developer/voice-agent-frontend/node_modules/.pnpm/[email protected][email protected][email protected]_bcf6a312fb11659b6e228704565bab3a/node_modules/next/dist/trace/trace.js:157:20)
at async DevServer.handleRequest (/Users/anibalguerrerohernandez/Desktop/Developer/voice-agent-frontend/node_modules/.pnpm/[email protected][email protected][email protected]_bcf6a312fb11659b6e228704565bab3a/node_modules/next/dist/server/dev/next-dev-server.js:336:24)
at async invokeRender (/Users/anibalguerrerohernandez/Desktop/Developer/voice-agent-frontend/node_modules/.pnpm/[email protected][email protected][email protected]_bcf6a312fb11659b6e228704565bab3a/node_modules/next/dist/server/lib/router-server.js:174:21)
at async handleRequest (/Users/anibalguerrerohernandez/Desktop/Developer/voice-agent-frontend/node_modules/.pnpm/[email protected][email protected][email protected]_bcf6a312fb11659b6e228704565bab3a/node_modules/next/dist/server/lib/router-server.js:353:24)
at async requestHandlerImpl (/Users/anibalguerrerohernandez/Desktop/Developer/voice-agent-frontend/node_modules/.pnpm/[email protected][email protected][email protected]_bcf6a312fb11659b6e228704565bab3a/node_modules/next/dist/server/lib/router-server.js:377:13)
at async Server.requestListener (/Users/anibalguerrerohernandez/Desktop/Developer/voice-agent-frontend/node_modules/.pnpm/[email protected][email protected][email protected]_bcf6a312fb11659b6e228704565bab3a/node_modules/next/dist/server/lib/start-server.js:142:13)
POST /api/webhooks/clerk 400 in 7ms
I've been having a go at it for a couple of days and haven't found anybody else having the same issue as me. Any help is appreciated!