feat: Add Clerk webhooks and authentication protection#103
feat: Add Clerk webhooks and authentication protection#103Jackson57279 merged 2 commits intoopen-lovable-v2from
Conversation
## Features - Added Clerk webhook endpoint with Svix signature verification - Implemented user sync to Convex database on user.created/user.updated events - Added user deletion handling for user.deleted webhooks - Added authentication protection to home page functionality ## Security - Webhook signatures verified using Svix - Only authenticated users can use the product - Input sanitization in user sync mutations ## UI Improvements - Rounded button corners (changed from sharp to rounded-md) - Updated style selectors, model dropdown, and input fields ## Configuration - Added CLERK_WEBHOOK_SECRET to .env.example 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
WalkthroughAdds Clerk webhook handling via a new API route that verifies Svix signatures and syncs/deletes users in Convex. Introduces Convex mutations for user sync and delete with cascading cleanup. Gates app submission by Clerk sign‑in state. Adds CLERK_WEBHOOK_SECRET to .env.example. Updates numerous dependencies in package.json. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant Clerk as Clerk
participant NextAPI as Next.js API Route (/api/webhooks/clerk)
participant Svix as Svix Verifier
participant Convex as ConvexHttpClient
participant Users as convex/users.ts
Clerk->>NextAPI: POST webhook (user.created|updated|deleted)
NextAPI->>Svix: Verify (svix-id, svix-timestamp, svix-signature, body)
alt Verification fails
Svix-->>NextAPI: Invalid
NextAPI-->>Clerk: 400/500
else Verification ok
Svix-->>NextAPI: Valid
alt user.created or user.updated
NextAPI->>Convex: users.syncUser({ id, email, fullName, avatarUrl, username })
Convex->>Users: syncUser mutation
Users-->>Convex: upsert result
Convex-->>NextAPI: ok
NextAPI-->>Clerk: 200
else user.deleted
NextAPI->>Convex: users.deleteUser({ id })
Convex->>Users: deleteUser mutation (cascade cleanup)
Users-->>Convex: delete result
Convex-->>NextAPI: ok
NextAPI-->>Clerk: 200
end
end
sequenceDiagram
autonumber
participant User as User
participant App as app/page.tsx
participant Clerk as Clerk Auth
User->>App: Click Submit
App->>Clerk: Check isSignedIn
alt Not signed in
App-->>User: Toast error + abort
else Signed in
App-->>User: Proceed with submission flow
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested labels
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
.env.example (1)
37-41: Keep env keys ordered to satisfy dotenv-linter
dotenv-linterexpectsCLERK_WEBHOOK_SECRETto appear beforeNEXT_PUBLIC_CLERK_PUBLISHABLE_KEY. Reordering the block will silence the warning and keep the file tidy.Apply this diff to fix the ordering:
-# Clerk Authentication configuration -NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY= -CLERK_SECRET_KEY= -CLERK_JWT_ISSUER_DOMAIN= -CLERK_WEBHOOK_SECRET= +# Clerk Authentication configuration +CLERK_JWT_ISSUER_DOMAIN= +CLERK_SECRET_KEY= +CLERK_WEBHOOK_SECRET= +NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Disabled knowledge base sources:
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
⛔ Files ignored due to path filters (1)
bun.lockis excluded by!**/*.lock
📒 Files selected for processing (5)
.env.example(1 hunks)app/api/webhooks/clerk/route.ts(1 hunks)app/page.tsx(6 hunks)convex/users.ts(1 hunks)package.json(3 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
convex/users.ts (2)
convex/_generated/server.js (2)
mutation(50-50)mutation(50-50)convex/_generated/server.d.ts (1)
MutationCtx(121-121)
🪛 dotenv-linter (3.3.0)
.env.example
[warning] 40-40: [UnorderedKey] The CLERK_WEBHOOK_SECRET key should go before the NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY key
(UnorderedKey)
Summary
Changes Made
Webhook Implementation
/app/api/webhooks/clerk/route.tsendpointuser.created,user.updated, anduser.deletedeventsDatabase Mutations
syncUsermutation inconvex/users.tsfor webhook-triggered user syncdeleteUsermutation for handling user deletion eventsAuthentication Protection
handleSubmitfunctionUI Improvements
rounded) to rounded (rounded-md)Configuration
CLERK_WEBHOOK_SECRETto.env.exampleSetup Instructions
https://yourdomain.com/api/webhooks/clerkuser.created,user.updated,user.deleted.env.localasCLERK_WEBHOOK_SECRETSecurity
✅ Webhook signatures verified using Svix
✅ Input sanitization in all user sync mutations
✅ Only authenticated users can use the product
✅ No sensitive data exposed in webhooks
Test Plan
🤖 Generated with Claude Code
Summary by CodeRabbit