Passkey Authentication

Register or log in a user using passkeys in Flutter

Register a new user with a passkey

To create a new user account with a passkey, provide the user’s email address or phone number to passage.register(). View a full registration implementation on GitHub.

final passage = PassageFlutter();

void register(String identifier) async {
  try {
    // Register user
    await passage.register(identifier);
    // Retrieve new authenticated user info
    final PassageUser user = await passage.getCurrentUser();
  } catch (error) {
    if (error is PassageError &&
        error.code == PassageErrorCode.userCancelled) {
      // User cancelled passkey prompt, do nothing.
    } else {
      // Optionally try an email or sms registration method (see next page)
    }
  }
}

Log in an existing user with a passkey

To authenticate an existing user with their passkey, use passage.login or passage.loginWithIdentifier (depending on platform). View a full registration implementation on GitHub.

void login(String identifier) async {
  try {
    if (kIsWeb) {
      // Web log in requires an email or phone for logging in
      await passage.loginWithIdentifier(identifier);
    } else {
      // iOS and Android do not accept an identifier.
      // These platforms will simply show any user passkeys associated with your app.
      await passage.login();
    }
    // Retrieve authenticated user info
    final PassageUser user = await passage.getCurrentUser();
  } catch (error) {
    if (error is PassageError &&
        error.code == PassageErrorCode.userCancelled) {
      // User cancelled passkey prompt, do nothing.
    } else {
      // Optionally try an email or login method (see next page)
    }
  }
}

Last updated