Skip to main content

User management

Use User methods to manage the current user's account. You can access the current user reactively with Clerk.userFlow or directly with Clerk.activeUser.

Reload user

val refreshedUser = user.reload()
val updatedUser = user.update {
    username = "janedoe"
    firstName = "Jane"
    lastName = "Doe"
}

Deprecated

Passing unsafeMetadata to user.update(...) is deprecated. Use user.updateMetadata(...) for partial metadata updates instead.

Use updateMetadata to update the user's unsafeMetadata. The submitted value is deep-merged into the existing metadata; pass JsonNull for any key whose value should be removed at any nesting level.

val updatedUser = user.updateMetadata(
    unsafeMetadata = buildJsonObject {
        put("theme", "dark")
    }
)

If you already have the metadata as a JSON string, you can use the UpdateMetadataParams overload instead:

val updatedUser = user.updateMetadata(
    User.UpdateMetadataParams(unsafeMetadata = """{"theme":"dark"}""")
)
val emailAddress = user.createEmailAddress("jane@example.com")
val phoneNumber = user.createPhoneNumber("+15551234567")

Create external account with OAuth

Create an external account with an OAuth provider (e.g., Google, GitHub, see all providers):

when (
    val result =
        user.createExternalAccount(
            User.CreateExternalAccountParams(
                provider = OAuthProvider.GOOGLE,
                redirectUrl = "myapp://callback"
            )
        )
) {
    is ClerkResult.Success -> {
        val externalAccountOAuth = result.value
    }
    is ClerkResult.Failure -> {
        // Handle the failure.
    }
}
val passkey = user.createPasskey()
val totp = user.createTOTP()
val verifiedTotp = user.verifyTOTP(code = "123456")
val deletedTotp = user.disableTOTP()
val backupCodes = user.createBackupCodes()
val sessions = user.getSessions()
when (
    val result =
        user.updatePassword(
            User.UpdatePasswordParams(
                currentPassword = "old-password",
                newPassword = "new-password",
                signOutOfOtherSessions = true
            )
        )
) {
    is ClerkResult.Success -> {
        val updatedUser = result.value
    }
    is ClerkResult.Failure -> {
        // Handle the failure.
    }
}
when (val result = user.setProfileImage(file)) {
    is ClerkResult.Success -> {
        val profileImage = result.value
    }
    is ClerkResult.Failure -> {
        // Handle the failure.
    }
}
val deletedProfileImage = user.deleteProfileImage()
val deletedUser = user.delete()

Feedback

What did you think of this content?

Last updated on