User Management

How to manage your authenticated user in Flutter

Get current user

Once your user has been authenticated, you can call passage.currentUser.userInfo() which will return a CurrentUser object. When the user is no longer authenticated, this method will return null.

Here's an example:

CurrentUser? currentUser = await passage.urrentUser.userInfo();
if (user) {
  print('User ID: ${currentUser.id}');
} else {
  print('No authenticated user');
}
View all available PassageUser properties

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 message where they'll need to confirm the change.

// Change email for authenticated user
String newEmail = 'new@email.com';
await passage.currentUser.changeEmail(newEmail);
 
// Change phone for authenticated user
String newPhone = '155555555555';
await passage.currentUser.changePhone(newPhone);
 

Manage user passkeys

The following CRUD operations are available for authenticated user passkeys. Note that each of these methods could throw an error that you'd need to handle.

// List user's passkeys
CurrentUser? currentUser = await passage.urrentUser.userInfo();
List<Passkey> userPasskeys = currentUser.webauthnDevices;
 
// Create a new passkey
Passkey newPasskey = await passage.currentUser.addPasskey();
 
// Edit name of passkey
String passkeyId = 'XXXXXXXXXXXXXX';
String passkeyNewName = 'My favorite passkey';
await passage.currentUser.editPasskey(passkeyId, passkeyNewName);
 
// Delete/revoke a passkey
await passage.currentUser.deletePasskey(passkeyId);
 

Sign out user

To sign out your user and remove their tokens from the user's device (more on this in the next section), you can simply call passage.currentUser.logout() .

await passage.currentUser.logout();