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.registerWithPasskey()
. View a full registration implementation on GitHub.
final passage = PassageFlutter();
void register(String identifier) async {
try {
// Register user
await passage.registerWithPasskey(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.loginWithPasskey
. View a full implementation on GitHub.
void login(String identifier) async {
try {
await _passage.loginWithPasskey(identifier);
// 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)
}
}
}