User Management
How to manage your authenticated user in Android
Get user
Once your user has been authenticated, you can call passage.currentUser.userInfo which will return a CurrentUserInfo instance. When the user is no longer authenticated, this method will return null.
Here’s an example:
suspend fun printUserId() {
val user = passage.currentUser.userInfo()
user?.let {
print("User ID: ${it.id}")
} ?: print("No authenticated user")
}And here’s what the CurrentUserInfo class looks like:
final class CurrentUserInfo(
/* When this user was created */
val createdAt: String? = null,
/* The user's email */
val email: String? = null,
/* Whether or not the user's email has been verified */
val emailVerified: Boolean? = null,
/* The userID (referred to as Handle) */
val id: String? = null,
/* The last time this user logged in */
val lastLoginAt: String? = null,
/* How many times the user has successfully logged in */
val loginCount: Int? = null,
/* The user's phone */
val phone: String? = null,
/* Whether or not the user's phone has been verified */
val phoneVerified: Boolean? = null,
/* User status: active, inactive, pending */
val status: String? = null,
/* When this user was last updated */
val updatedAt: String? = null,
/* The user's metadata */
val userMetadata: Any? = null,
/* Whether or not the user has authenticated via webAuthn before (if len(WebAuthnDevices) > 0) */
val webauthn: Boolean? = null,
/* The list of devices this user has authenticated with via webAuthn */
val webauthnDevices: List<PassageCredential>? = null,
/* List of credential types that user has created */
val webauthnTypes: List<String>? = null
)Methods for updating user
Change contact info
To change the user’s phone number or email, you can follow the examples below. Note that the user will receive a verification email or text message where they’ll need to confirm the change.
suspend fun changePhone(newPhone: String) {
try {
passage.currentUser.changePhone(newPhone)
} catch (e: PassageUserException) {
handleUserException(e)
}
}
suspend fun changeEmail(newEmail: String) {
try {
passage.currentUser.changeEmail(newEmail)
} catch (e: PassageUserException) {
handleUserException(e)
}
}
fun handleUserException(e: PassageUserException) {
when (e) {
is PassageUserRequestException -> {
// User's phone or email was invalid
}
is PassageUserUnauthorizedException -> {
// User is not authorized to make this change
}
}
}Manage user passkeys
The following CRUD operations are available for user passkey credentials:
// Create a new passkey
passage.currentUser.addPasskey()
// Get user's device passkeys
passage.currentUser.passkeys()
// Edit a passkey name
passage.currentUser.editPasskey(devicePasskeyId, newName)
// Delete a passkey device
// NOTE: This does NOT remove the passkey from the user's device, but it revokes the passkey
passage.currentUser.deletePasskey(devicePasskeyId)Sign out user
To log out your user and remove their tokens from the PassageTokenStore (more on this in the next section), you can simply call passage.currentUser.logout() .
suspend fun logout() {
passage.currentUser.logout()
// Go to login screen
}