Clerk

Flux — Theme

Clerk is a complete authentication and user management solution that eliminates the complexity of building auth from scratch. With pre-built UI components, social logins, multi-factor authentication, and session management, Clerk lets you add secure authentication to your Astro and React applications in minutes while maintaining best security practices and providing excellent developer experience.

Installing Clerk

Clerk provides official packages for Astro and React. Start by creating a free Clerk account, which gives you a publishable key and secret key. Install the appropriate package based on your framework, then configure environment variables for authentication to work across your application.

Terminal

Creating Sign-In Pages

Clerk provides pre-built UI components for sign-in, sign-up, and user profile pages. These components handle all the complexity of authentication flows, including email/password, social logins, magic links, and multi-factor authentication. Customize the appearance to match your brand.

Terminal

Protecting Routes

Protect pages and API routes by checking authentication status. Clerk provides helpers to get the current user's authentication state. Redirect unauthenticated users to the sign-in page and conditionally render content based on user roles or permissions.

Terminal

Using Clerk in React Components

Clerk's React hooks provide authentication state and user information in client components. Use these hooks to conditionally render UI, display user info, and handle sign-out. The UserButton component provides a dropdown menu with account management options.

Terminal