ClerkService
ClerkService is the reactive core of ngx-clerk: an injectable, providedIn: 'root' service
that wraps the Clerk instance in Angular signals. provideClerk()
calls initialize() once at application startup — everything else below is safe to call
anywhere the service is injected.
initialize(options: ClerkInitOptions): Promise<void>is internal.provideClerk()calls it once during application bootstrap; calling it yourself logs a warning and resolves immediately without re-initializing.
Signals
| Signal | Type | Description |
|---|---|---|
clerk() |
Clerk or null |
the Clerk instance, or null until Clerk has loaded |
client() |
ClientResource or null |
the current Clerk client resource |
session() |
SignedInSessionResource or null |
the active session, or null when not signed in |
user() |
UserResource or null |
the current user, or null when not signed in |
organization() |
OrganizationResource or null |
the active organization, or null when none is active |
isLoaded() |
boolean |
whether Clerk has finished loading |
isSignedIn() |
boolean |
whether a user is currently signed in |
userId() |
string or null |
the current user’s ID |
orgId() |
string or null |
the active organization’s ID |
sessionId() |
string or null |
the active session’s ID |
orgRole() |
string or null |
the current user’s role in the active organization |
orgSlug() |
string or null |
the active organization’s slug |
sessionClaims() |
JwtPayload or null |
the claims of the active session’s JWT |
actor() |
ActClaim or null |
the actor (impersonation) claim of the active session |
signIn() |
SignInResource or null |
the active sign-in attempt resource |
signUp() |
SignUpResource or null |
the active sign-up attempt resource |
sessions() |
SessionResource[] |
every session registered on the current client device |
membership() |
OrganizationMembershipResource or null |
the current user’s membership in the active organization |
isSignedIn()is!!user()?.id— it does not check session status. A Clerk Core 3 session with statuspending(for example, an incomplete organization-selection task) still reportsisSignedIn() === true, since the pending session already carries a fulluser. This differs from upstream SDKs’useAuth(), which treatspendingas signed out by default (treatPendingAsSignedOut). ngx-clerk has no session-task UI yet, so checksession()?.statusyourself if your instance can put users into a pending state. The same applies across the whole authorization surface:has(), the*clerkProtectdirective, thecanActivateClerkandcanActivateProtectguards, and*clerkSignedInall treat a pending session as signed in and authorized — a pending session still carriesorgIdandorgRoleclaims thathas()will evaluate. Apps that enable session tasks (for example, forced organization selection) should gate onsession()?.status === 'active'themselves until ngx-clerk ships task routing.
import { Component, inject } from '@angular/core';
import { ClerkService } from 'ngx-clerk';
@Component({ selector: 'app-profile', template: `…` })
export class ProfileComponent {
protected readonly clerk = inject(ClerkService);
}
See Reading auth state for template examples and the
toObservable() interop, and Organizations & roles for the
org-specific signals.
Reacting to signals with effect()
Every signal above is a plain Angular signal, so effect() re-runs whenever one it reads
changes — useful for side effects that aren’t rendering, like reporting the signed-in user to
an analytics tool:
import { Component, effect, inject } from '@angular/core';
import { ClerkService } from 'ngx-clerk';
@Component({ selector: 'app-root', template: `…` })
export class AppComponent {
private readonly clerk = inject(ClerkService);
constructor() {
effect(() => {
const userId = this.clerk.userId();
if (userId) {
myAnalytics.identify(userId);
}
});
}
}
Methods
Authorization & tokens
| Method | Description |
|---|---|
has(params: CheckAuthorizationParams): boolean |
Checks a role, permission, feature, or plan. false while signed out. See Organizations & roles. |
getToken(options?: GetTokenOptions): Promise<string \| null> |
Returns the current session JWT, optionally for a named template. Resolves to null when there’s no active session. |
setActive(params: SetActiveParams): Promise<void> |
Sets the active session and/or organization. |
handleRedirectCallback(params?: HandleOAuthCallbackParams): Promise<void> |
Completes an OAuth/SSO redirect flow. |
await clerk.setActive({ organization: 'org_123' });
Appearance & localization
| Method | Description |
|---|---|
updateAppearance(opts: ClerkOptions['appearance']): void |
Updates the global appearance configuration for all Clerk components. |
updateLocalization(opts: ClerkOptions['localization']): void |
Updates the localization configuration for all Clerk components. |
updateClerkOptions(options: ClerkUpdateOptions): void |
Updates appearance and/or localization together — ClerkUpdateOptions is { localization?, appearance? }. |
Open/close UI
The imperative equivalent of mounting the matching component from Components — open one from a click handler instead of always rendering the component:
| Method | Description |
|---|---|
openSignIn(opts?: SignInProps): void / closeSignIn(): void |
Opens/closes the sign-in modal. |
openSignUp(opts?: SignUpProps): void / closeSignUp(): void |
Opens/closes the sign-up modal. |
openUserProfile(opts?: UserProfileProps): void / closeUserProfile(): void |
Opens/closes the user profile modal. |
openOrganizationProfile(opts?: OrganizationProfileProps): void / closeOrganizationProfile(): void |
Opens/closes the organization profile modal. |
openCreateOrganization(opts?: CreateOrganizationProps): void / closeCreateOrganization(): void |
Opens/closes the create organization modal. |
Redirects
| Method | Description |
|---|---|
redirectToSignIn(opts?: SignInRedirectOptions): void |
Redirects to the Clerk sign-in page. |
redirectToSignUp(opts?: SignUpRedirectOptions): void |
Redirects to the Clerk sign-up page. |
Sign out
| Method | Description |
|---|---|
signOut(opts?: SignOutOptions): Promise<void> |
Signs out the current user. Pass sessionId to sign out of one specific session; omit it to sign out of every session on the device. |
await clerk.signOut({ redirectUrl: '/' });
Handling errors
ngx-clerk re-exports Clerk’s error classes and type guards from @clerk/shared/error:
ClerkAPIResponseError, ClerkOfflineError, ClerkRuntimeError, EmailLinkErrorCodeStatus,
isClerkAPIResponseError, isClerkRuntimeError, isEmailLinkError, isKnownError,
isMetamaskError.
Methods that call the Clerk API — setActive(), signOut(), and the sign-in/up flows inside
the mounted components — can reject with a ClerkAPIResponseError. Narrow it with
isClerkAPIResponseError to read the structured errors array:
import { isClerkAPIResponseError } from 'ngx-clerk';
try {
await clerk.setActive({ organization: orgId });
} catch (error) {
if (isClerkAPIResponseError(error)) {
console.error(error.errors[0]?.longMessage ?? error.errors[0]?.message);
} else {
throw error;
}
}
See Session tokens for the ClerkOfflineError /
isClerkRuntimeError pattern specific to getToken().