User

@Serializable
data class User(val backupCodeEnabled: Boolean? = null, val createdAt: Long? = null, val createOrganizationEnabled: Boolean? = null, val createOrganizationsLimit: Int? = null, val deleteSelfEnabled: Boolean = false, val emailAddresses: List<EmailAddress>, val enterpriseAccounts: List<EnterpriseAccount>? = null, val externalAccounts: List<ExternalAccount>, val firstName: String? = null, val hasImage: Boolean, val id: String, val imageUrl: String, val lastSignInAt: Long? = null, val lastName: String? = null, val legalAcceptedAt: Long? = null, val organizationMemberships: List<OrganizationMembership>? = null, val passkeys: List<Passkey>, val passwordEnabled: Boolean, val phoneNumbers: List<PhoneNumber>, val primaryEmailAddressId: String? = null, val primaryPhoneNumberId: String? = null, val publicMetadata: JsonObject? = null, val privateMetadata: JsonObject? = null, val totpEnabled: Boolean, val twoFactorEnabled: Boolean, val updatedAt: Long, val unsafeMetadata: JsonObject? = null, val username: String? = null)

The User object holds all of the information for a single user of your application and provides a set of methods to manage their account.

Each user has a unique authentication identifier which might be their email address, phone number, or a username.

A user can be contacted at their primary email address or primary phone number. They can have more than one registered email address, but only one of them will be their primary email address. This goes for phone numbers as well; a user can have more than one, but only one phone number will be their primary. At the same time, a user can also have one or more external accounts by connecting to social providers such as Google, Apple, Facebook, and many more.

Finally, a User object holds profile data like the user's name, profile picture, and a set of metadata that can be used internally to store arbitrary information. The metadata are split into publicMetadata and privateMetadata. Both types are set from the Backend API, but public metadata can also be accessed from the Frontend API.

The Clerk SDK provides some helper methods on the User object to help retrieve and update user information and authentication status.

Constructors

Link copied to clipboard
constructor(backupCodeEnabled: Boolean? = null, createdAt: Long? = null, createOrganizationEnabled: Boolean? = null, createOrganizationsLimit: Int? = null, deleteSelfEnabled: Boolean = false, emailAddresses: List<EmailAddress>, enterpriseAccounts: List<EnterpriseAccount>? = null, externalAccounts: List<ExternalAccount>, firstName: String? = null, hasImage: Boolean, id: String, imageUrl: String, lastSignInAt: Long? = null, lastName: String? = null, legalAcceptedAt: Long? = null, organizationMemberships: List<OrganizationMembership>? = null, passkeys: List<Passkey>, passwordEnabled: Boolean, phoneNumbers: List<PhoneNumber>, primaryEmailAddressId: String? = null, primaryPhoneNumberId: String? = null, publicMetadata: JsonObject? = null, privateMetadata: JsonObject? = null, totpEnabled: Boolean, twoFactorEnabled: Boolean, updatedAt: Long, unsafeMetadata: JsonObject? = null, username: String? = null)

Types

Link copied to clipboard
@Serializable
data class CreateExternalAccountParams(val provider: OAuthProvider, val redirectUrl: String = RedirectConfiguration.DEFAULT_REDIRECT_URL, val oidcPrompt: String? = null, val oidcLoginHint: String? = null)

Parameters for creating an external account connection.

Link copied to clipboard
@Serializable
data class UpdateParams(val firstName: String? = null, val lastName: String? = null, val username: String? = null, val primaryEmailAddressId: String? = null, val primaryPhoneNumberId: String? = null, val profileImageId: String? = null, val publicMetadata: String? = null, val privateMetadata: String? = null)

Parameters for updating a user's profile information.

Link copied to clipboard
@Serializable
data class UpdatePasswordParams(val currentPassword: String? = null, val newPassword: String, val signOutOfOtherSessions: Boolean = false)

Parameters for updating a user's password.

Properties

Link copied to clipboard
@SerialName(value = "backup_code_enabled")
val backupCodeEnabled: Boolean? = null

A boolean indicating whether the user has enabled Backup codes.

Link copied to clipboard
@SerialName(value = "created_at")
val createdAt: Long? = null

Date when the user was first created.

Link copied to clipboard
@SerialName(value = "create_organization_enabled")
val createOrganizationEnabled: Boolean? = null

A boolean indicating whether the organization creation is enabled for the user or not.

Link copied to clipboard
@SerialName(value = "create_organizations_limit")
val createOrganizationsLimit: Int? = null

An integer indicating the number of organizations that can be created by the user. If the value is 0, then the user can create unlimited organizations. Default is null.

Link copied to clipboard
@SerialName(value = "delete_self_enabled")
val deleteSelfEnabled: Boolean = false

A boolean indicating whether the user is able to delete their own account or not.

Link copied to clipboard
@SerialName(value = "email_addresses")
val emailAddresses: List<EmailAddress>

An array of all the EmailAddress objects associated with the user. Includes the primary.

Link copied to clipboard
@SerialName(value = "enterprise_accounts")
val enterpriseAccounts: List<EnterpriseAccount>? = null

A list of enterprise accounts associated with the user.

Link copied to clipboard
@SerialName(value = "external_accounts")
val externalAccounts: List<ExternalAccount>

An array of all the ExternalAccount objects associated with the user via OAuth. Note: This includes both verified & unverified external accounts.

Link copied to clipboard
@SerialName(value = "first_name")
val firstName: String? = null

The user's first name.

Link copied to clipboard
@SerialName(value = "has_image")
val hasImage: Boolean

A boolean to check if the user has uploaded an image or one was copied from OAuth. Returns false if Clerk is displaying an avatar for the user.

Link copied to clipboard
val id: String

The unique identifier for the user.

Link copied to clipboard
@SerialName(value = "image_url")
val imageUrl: String

Holds the default avatar or user's uploaded profile image

Link copied to clipboard
@SerialName(value = "last_name")
val lastName: String? = null

The user's last name.

Link copied to clipboard
@SerialName(value = "last_sign_in_at")
val lastSignInAt: Long? = null

Date when the user last signed in. May be empty if the user has never signed in.

Link copied to clipboard
@SerialName(value = "legal_accepted_at")
val legalAcceptedAt: Long? = null

The date on which the user accepted the legal requirements if required.

Link copied to clipboard
@SerialName(value = "organization_memberships")
val organizationMemberships: List<OrganizationMembership>? = null

A list of OrganizationMemberships representing the list of organizations the user is member with.

Link copied to clipboard

An array of all the Passkey objects associated with the user.

Link copied to clipboard
@SerialName(value = "password_enabled")
val passwordEnabled: Boolean

A boolean indicating whether the user has a password on their account.

Link copied to clipboard
@SerialName(value = "phone_numbers")
val phoneNumbers: List<PhoneNumber>

An array of all the PhoneNumber objects associated with the user. Includes the primary.

Link copied to clipboard
@SerialName(value = "primary_email_address_id")
val primaryEmailAddressId: String? = null

The unique identifier for the EmailAddress that the user has set as primary.

Link copied to clipboard
@SerialName(value = "primary_phone_number_id")
val primaryPhoneNumberId: String? = null

The unique identifier for the PhoneNumber that the user has set as primary.

Link copied to clipboard
@SerialName(value = "private_metadata")
val privateMetadata: JsonObject? = null

Metadata that can be read from the Frontend API and Backend API and can be set only from the Backend API.

Link copied to clipboard
@SerialName(value = "public_metadata")
val publicMetadata: JsonObject? = null

Metadata that can be read from the Frontend API and Backend API and can be set only from the Backend API.

Link copied to clipboard
@SerialName(value = "totp_enabled")
val totpEnabled: Boolean

A boolean indicating whether the user has enabled TOTP by generating a TOTP secret and verifying it via an authenticator app.

Link copied to clipboard
@SerialName(value = "two_factor_enabled")
val twoFactorEnabled: Boolean

A boolean indicating whether the user has enabled two-factor authentication.

Link copied to clipboard

Extension property that returns a list of OAuth providers that the user has not yet connected.

Link copied to clipboard
@SerialName(value = "unsafe_metadata")
val unsafeMetadata: JsonObject? = null

Metadata that can be read and set from the Frontend API. One common use case for this attribute is to implement custom fields that will be attached to the User object. Please note that there is also an unsafeMetadata attribute in the SignUp object. The value of that field will be automatically copied to the user's unsafe metadata once the sign up is complete.

Link copied to clipboard
@SerialName(value = "updated_at")
val updatedAt: Long

Date of the last time the user was updated.

Link copied to clipboard
val username: String? = null

The user's username.

Functions

Link copied to clipboard

Retrieves the active sessions for the current user or the user with the given session ID.

Link copied to clipboard

Retrieves all sessions for the current user or the user with the given session ID.

Link copied to clipboard

Verifies a TOTP (Time-based One-Time Password) code to complete the TOTP setup process.

Link copied to clipboard

Generates backup codes for the current user's account.

Link copied to clipboard

Creates a new email address for the current user or the user with the given session ID.

Link copied to clipboard

Adds an external account for the user. A new ExternalAccount will be created and associated with the user. This method is useful if you want to allow an already signed-in user to connect their account with an external provider, such as Facebook, GitHub, etc., so that they can sign in with that provider in the future.

Link copied to clipboard

Creates a new passkey for the current user or the user with the given session ID.

Link copied to clipboard

Creates a new phone number for the current user or the user with the given session ID.

Link copied to clipboard

Creates a new TOTP (Time-based One-Time Password) configuration for the current user.

Link copied to clipboard

Deletes the current user, or the user with the given session ID, from the Clerk API.

Link copied to clipboard
suspend fun User.deletePassword(currentPassword: String): ClerkResult<User, ClerkErrorResponse>

Deletes the current user's password, or the user with the given session ID, using the Clerk API.

Link copied to clipboard

Deletes the current user's profile image, or the user with the given session ID, from the Clerk API.

Link copied to clipboard

Deletes the TOTP (Time-based One-Time Password) configuration for the current user.

Link copied to clipboard

Retrieves all email addresses associated with the current user or the user with the given session ID.

Link copied to clipboard

Extension function that returns the user's full name by combining first and last names.

Link copied to clipboard

Retrieves the current user, or the user with the given session ID, from the Clerk API.

Link copied to clipboard

Retrieves all phone numbers associated with the current user or the user with the given session ID.

Link copied to clipboard

Update the current user's profile image, or the user with the given session ID, with the provided image data.

Link copied to clipboard

Updates the current user, or the user with the given session ID, with the provided parameters.

Link copied to clipboard

Updates the current user's password, or the user with the given session ID, using the Clerk API.