Sync Clerk data to your app with webhooks [S2 E4]

Sync Clerk data to your app with webhooks [S2 E4]

Machine-readable: Markdown · JSON API · Site index

Поделиться Telegram VK Бот
Транскрипт Скачать .md
Анализ с AI

Оглавление (1 сегментов)

Segment 1 (00:00 - 02:00)

if you're using Clerk and you want to own your data you can use Clerk web hooks to sync Clerk data back into your own database so first things first you need to set up a way to tunnel your local server if you want to test your web hook to the public internet i'm going to use Enro and there is a guide here if you haven't used it before to set it up for yourself next we're going to set up a web hook endpoint this is inside of our Clerk dashboard so we go to our application we go to configure and then from the side menu down here we go to web hooks and now we want to set up an endpoint now when you're using Enrock it either gives you a random domain or if you want you can have a custom domain mine is a custom domain so I'm going to use that in this case I want to listen to all user related events now the one thing I need from here is a signing secret so you need to copy this and bring it back to your application and now I'm just going to paste it over here so now we need to add sweets this is to verify the web hook secret to make sure that the incoming request is actually coming from clerk so let's go and install this and then now we want to create a round handler to receive this web hook event using this verify web hook function from clerk package it reads your signing secret looks for the headers of the payload of this request and verifies if it is actually a valid request and then it proceeds now we can also uh narrow this events down so we get some type inference this is where we're going to actually add the user to our database so I've set up Prisma by defining my schema and a user model that maps to the fields that I want to save from clerk i've created a Prisma client that is a generated Prisma client depending or based on my schema and a create user function that talks to the Prisma client and creates a user once we receive this data from our web hook so just going back into our web hook as the last step I wanted to show you that under the user created instead of just logging the user now I'm extracting the email address first name and last name from the data and then I'm creating the user object and using this create user function that we just created in our lip folder i'm going to create the user so let's test this out if I now go ahead and sign into my application I'm now logged in if I go to cleric dashboard and refresh I have my user inside of my clerk dashboard i'm running Prisma Studio to also look inside my database and I can see the user is now created inside of my database as well and that's how you can sync clerk data back into your own database using clerk web hooks
Ctrl+V

Экстракт Знаний в Telegram

Экстракты и дистилляты из лучших YouTube-каналов — сразу после публикации.

Подписаться

Дайджест Экстрактов

Лучшие методички за неделю — каждый понедельник