sendLink method

  1. @override
Future<void> sendLink(
  1. String email
)
override

Implementation

@override
Future<void> sendLink(String email) async {
  value = const SendingLink();

  try {
    await auth.sendSignInLinkToEmail(
      email: email,
      actionCodeSettings: actionCodeSettings,
    );

    value = const AwaitingDynamicLink();

    final linkData = await _links.onLink.first;
    final link = linkData.link.toString();

    if (auth.isSignInWithEmailLink(link)) {
      value = const SigningIn();
      final userCredential =
          await auth.signInWithEmailLink(email: email, emailLink: link);

      final user = userCredential.user;

      if (user != null) {
        value = SignedIn(user);
      }
    } else {
      throw FirebaseAuthException(
        code: 'invalid-email-signin-link',
        message: 'Invalid email sign in link',
      );
    }
  } on Exception catch (e) {
    value = AuthFailed(e);
  }
}