User Management

How to manage your authenticated user in Flutter

Get Current User

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

Here's an example:

PassageUser? passageUser = await passage.getCurrentUser();
if (user) {
  print('User ID: ${}');
} else {
  print('No authenticated user');

You can find all of the available properties on PassageUser here.

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 = '[email protected]';
await passage.changeEmail(newEmail);

// Change phone for authenticated user
String newPhone = '155555555555';
await passage.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
PassageUser? user = await passage.getCurrentUser();
List<Passkey> userPasskeys = user.webauthnDevices;

// Create a new passkey
Passkey newPasskey = await passage.addPasskey();

// Edit name of passkey
String passkeyId = 'XXXXXXXXXXXXXX';
String passkeyNewName = 'My favorite passkey';
await passage.editPasskeyName(passkeyId, passkeyNewName);

// Delete/revoke a passkey
await passage.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.signOut() .

await passage.signOut();

Last updated