Override Clerk interfaces with custom types
Clerk provides TypeScript interfaces that you can use to define custom types for your application. Custom types provide auto-complete and prevent TypeScript errors. You can define custom types for the following:
- ClerkAuthorization
- CustomJwtSessionClaims
- OrganizationPublicMetadata
- OrganizationInvitationPublicMetadata
- OrganizationMembershipPublicMetadata
- SignUpUnsafeMetadata
- UserPublicMetadata
- UserPrivateMetadata
- UserUnsafeMetadata
Example: custom JWT claims
To override an interface, you must define a global type, as shown in the following example:
- In your application's root folder, add a typesdirectory.
- Inside of the typesdirectory, add aglobals.d.tsfile.
- Create the CustomJwtSessionClaimsinterface and declare it globally.
- Add the custom claims to the CustomJwtSessionClaimsinterface.
export {}
declare global {
  interface CustomJwtSessionClaims {
    firstName?: string
    primaryEmail?: string
    metadata: {
      onboardingComplete?: boolean
    }
  }
}Example: custom roles and permissions
When defining custom types for roles and permissions:
- Custom permissions are merged with system permissions
- Custom roles completely replace default roles (org:adminandorg:member)
export {}
declare global {
  interface ClerkAuthorization {
    permission: 'org:quiz:create' | 'org:quiz:grade' | 'org:quiz:read' | 'org:quiz:fill'
    role: 'org:super_admin' | 'org:teacher' | 'org:student'
  }
}Feedback
Last updated on