Authentication is essential for all modern web applications. Instead of creating and integrating authentication to protect our application we can choose one from wide range of IAM platforms available.

Clerk is one of the modern authentication/user management platform that provides:

  1. Sign In/Sign Up Forms
  2. Social Login
  3. User Profile & Roles Management
  4. JWT authentication

To configure an account in Clerk platform, follow the steps below in the Clerk platform:

  1. Sign Up to Clerk account and create any application. We can create separate instances for development and production of the same application.
  2. Add organization to the created application so that users created under the application can be mapped to the organization.
  3. Under Configuration, we can setup Roles & Permissions, API keys, Account portal, webhooks, etc.
  4. Copy the frontend publishable key, backend secret key, JWT key, JWT url, issuer and Webhook API key.

The steps to integrate Clerk into React application:

  1. Create a React application with Node, Express for the backend.
  2. Install clerk using npm install @clerk/clerk-react
  3. Setup Clerk by wrapping the application inside Clerk Provider as shown below.
  4. Configure the Clerk keys to the application’s environment variables file.
  5. We can get jwt token signed by clerk using useAuth as shown below and this token is passed in headers for the api calls.
  6. We can also add webhooks to our application to integrate the events that occur in clerk such as user creation, update or delete so that the changes will be synced to our application UI and database.

In this way, any modern authentication system can be integrated to React application for providing better user management and security.

Leave a Reply