DEV Community

Cover image for Sync clerk users to your database using Webhooks: A Step-by-Step Guide

Sync clerk users to your database using Webhooks: A Step-by-Step Guide

Amrasakpare Lawrence on October 13, 2023

Hey guys, If you've ever struggled with syncing user data stored on Clerk with your MongoDB database while using React (Vite) for your application,...
Collapse
 
sanntoryu7 profile image
Sanntoryu7

hello, I am working on a school project using Clerk and that was exactly what I needed ! I followed all the steps but I have a problem in my db. It created an "test" db with an "users" collection but there no users information at all !

Collapse
 
devlawrence profile image
Amrasakpare Lawrence

what database are you using?

Collapse
 
gjlander profile image
gjlander

Awesome guide! I managed to get it to work following your instructions very carefully. And after several hour of debugging figured out that this line: app.use(express.json());
was the reason it wasn't working when I tried to integrate it with the rest of my backend. This gave me a 400 error, so if you're also getting that, check you don't have a middleware getting in the way

Collapse
 
devlawrence profile image
Amrasakpare Lawrence

Thanks gjlander for this correction🙌.

Collapse
 
voidvampire profile image
Yash Dinesh Singh

let's say my app has 10 protected routes and 3 unprotected routes (/, sign-in, sign-up), how can I implement it?

Collapse
 
devlawrence profile image
Amrasakpare Lawrence

Hey Yash. Just to be sure. Are you asking how you can implement protected routes to your application?

Collapse
 
maven11 profile image
deepak verma

I am unable to get output in my terminal I don't know whats the issue

Collapse
 
devlawrence profile image
Amrasakpare Lawrence

hey verma, just make sure you have the right packages installed, and also check the webhook endpoint. Or you can show me a screenshot of what you are getting on your terminal

Collapse
 
maven11 profile image
deepak verma

yeah I checked it but everything is right, can I send you the repo. link so you can see whats wrong in there

Thread Thread
 
devlawrence profile image
Amrasakpare Lawrence

yea you can.

Thread Thread
 
maven11 profile image
deepak verma

github.com/deepakk-t7/auth-db-testing . I
cant log the output in my console

Thread Thread
 
devlawrence profile image
Amrasakpare Lawrence

Hey deepak. I just went through your code. it's a next.js project. but the article was for vite. but I do have a link to a video that will show you how to do the same thing. because the approach I used on vite won't work with a next js project. Here is the link to the video. 👇
youtu.be/NgBxrIC1eHM?si=Y6Vov0rfjJ...

Thread Thread
 
maven11 profile image
deepak verma

Thanks for your help! You are a great guy Could we connect somewhere for future questions?

Thread Thread
 
devlawrence profile image
Amrasakpare Lawrence

Yea for sure...you can chat me on Twitter

twitter.com/Lawrence_sticks