--- title: Configure Clerk Authentication Service - Step-by-Step Guide description: >- Learn how to set up Clerk authentication with environment variables and webhooks. tags: - Clerk Authentication - Environment Variables - Webhook Configuration --- # Configure Clerk Authentication Service Go to [Clerk](https://clerk.com?utm_source=lobehub\&utm_medium=docs) to register and create an application to obtain the corresponding Public Key and Secret Key. ## Get Environment Variables ### Add Public and Private Key Environment Variables Add `NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY` and `CLERK_SECRET_KEY` environment variables. You can click on the "API Keys" in the menu and copy the corresponding values to get these environment variables. {'Find > The environment variables required for this step are as follows: ```shell NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=pk_live_xxxxxxxxxxx CLERK_SECRET_KEY=sk_live_xxxxxxxxxxxxxxxxxxxxxx ``` ### Create and Configure Webhook in Clerk Since we let Clerk fully handle user authentication and management, we need Clerk to notify our application and store the changes in the user lifecycle (create, update, delete). We achieve this by using the Webhook provided by Clerk. We need to add an endpoint in Clerk's Webhooks to inform Clerk to send notifications to this endpoint when a user's information changes. {'Add > Fill in your project URL in the endpoint, such as `https://your-project.com/api/webhooks/clerk`. Then, subscribe to events by checking the three user events (`user.created`, `user.deleted`, `user.updated`), and click create. The `https://` in the URL is essential to maintain the integrity of the URL. {'Configure > ### Add Webhook Secret to Environment Variables After creating, you can find the secret of this Webhook in the bottom right corner: {'View > The environment variable corresponding to this secret is `CLERK_WEBHOOK_SECRET`: ```shell CLERK_WEBHOOK_SECRET=whsec_xxxxxxxxxxxxxxxxxxxxxx ``` By following these steps, you have successfully configured the Clerk authentication service.