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();voidregister(String identifier) async {try {// Register userawait passage.register(identifier);// Retrieve new authenticated user infofinalPassageUser user =await passage.getCurrentUser(); } catch (error) {if (error isPassageError&& 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.
voidlogin(String identifier) async {try {if (kIsWeb) {// Web log in requires an email or phone for logging inawait 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 infofinalPassageUser user =await passage.getCurrentUser(); } catch (error) {if (error isPassageError&& error.code ==PassageErrorCode.userCancelled) {// User cancelled passkey prompt, do nothing. } else {// Optionally try an email or login method (see next page) } }}