Welcome to ngx-clerk, an unofficial Angular package that integrates with Clerk.
Disclaimer: This unofficial package is not affiliated with Clerk.com. It is an unofficial project that aims to provide a seamless integration of Clerk features into Angular applications.
- Angular version 19 or higher.
- Clerk Core 3 (ClerkJS v6).
- Currently, this package supports client-side operations only. Server-Side Rendering (SSR) is not supported at the moment.
npm i ngx-clerk- Create an app in Clerk Dashboard and get the Publishable Key.
- Add
provideClerk()to your app config:
// app.config.ts
import { ApplicationConfig } from '@angular/core';
import { provideRouter } from '@angular/router';
import { provideClerk } from 'ngx-clerk';
import { routes } from './app.routes';
export const appConfig: ApplicationConfig = {
providers: [
provideRouter(routes),
provideClerk({
publishableKey: 'pk_test_XXXXXXXX',
}),
],
};- Use Clerk components in your templates:
// app.component.ts
import { Component } from '@angular/core';
import { RouterOutlet } from '@angular/router';
import { ClerkUserButtonComponent } from 'ngx-clerk';
@Component({
selector: 'app-root',
standalone: true,
imports: [RouterOutlet, ClerkUserButtonComponent],
template: `
<clerk-user-button />
<router-outlet />
`,
})
export class AppComponent {}- Protect routes with the
canActivateClerkguard:
// app.routes.ts
import { Routes } from '@angular/router';
import { canActivateClerk } from 'ngx-clerk';
export const routes: Routes = [
{ path: '', component: HomeComponent },
{
path: 'dashboard',
component: DashboardComponent,
canActivate: [canActivateClerk],
},
];- Access auth state via signals on
ClerkService:
import { Component, inject } from '@angular/core';
import { ClerkService } from 'ngx-clerk';
@Component({
selector: 'app-dashboard',
template: `
@if (clerk.user(); as user) {
<p>Hello {{ user.firstName }}</p>
}
`,
})
export class DashboardComponent {
clerk = inject(ClerkService);
}-
Clerk UI Components: All Clerk UI components are available and prefixed with
clerk-:<clerk-sign-in /><clerk-sign-up /><clerk-user-profile /><clerk-user-button /><clerk-organization-profile /><clerk-organization-switcher /><clerk-organization-list /><clerk-create-organization /><clerk-waitlist /><clerk-user-avatar /><clerk-pricing-table />
-
ClerkService: Central service exposing auth state as Angular signals:
user()- CurrentUserResourceornullsession()- CurrentActiveSessionResourceornullorganization()- CurrentOrganizationResourceornullclient()- CurrentClientResourceornullclerk()- The Clerk instance ornullisLoaded()- Whether Clerk has finished loadingisSignedIn()- Whether the user is signed inuserId()- Current user ID ornullorgId()- Current organization ID ornull
-
canActivateClerk: A functional route guard that protects routes and waits for Clerk to load before checking auth state.
See MIGRATION.md for a detailed upgrade guide.