signInWithApple method

Future<void> signInWithApple({
  1. String? redirect,
})

Implementation

Future<void> signInWithApple({String? redirect}) async {
  try {
    businessController.showDialogProgress(show: true);
    var firebaseAuth = FirebaseAuth.instance;
    //final result = await TheAppleSignIn.performRequests([AppleIdRequest(requestedScopes: scopes)]);
    UserCredential userCredential;
    // Trigger the authentication flow
    final credential = await SignInWithApple.getAppleIDCredential(
      scopes: [
        AppleIDAuthorizationScopes.email,
        AppleIDAuthorizationScopes.fullName,
      ],
      // webAuthenticationOptions: WebAuthenticationOptions(
      //   clientId: 'your_client_id',
      //   redirectUri: Uri.parse('your_redirect_uri'),
      // ),
    );

    // Create a new credential
    final OAuthCredential appleAuthCredential = OAuthProvider("apple.com").credential(
      idToken: credential.identityToken,
      accessToken: credential.authorizationCode,
    );

    // Once signed in, get the credential
    userCredential = await firebaseAuth.signInWithCredential(appleAuthCredential);

    UserModel user = UserModel();
    user = await userRepository.getUserUI(currentUser: userCredential.user);
    user.userName = TypeSafeConversion.nullSafeString(userCredential.user?.email);
    user.motDePasse = '.';
    user.userCreated = 'apple';

    await loginRegisterProvider(redirect: redirect, user: user);
  } on PlatformException catch (ex, trace) {
    logCat('code:${ex.code} | message:${ex.message}');
    businessController.showDialogProgress(show: false);
    DialogView.showAlertDialog(msg: getErrorMessage(ex));
    logError(ex, trace: trace, position: 'signInWithApple');
    signOut();
    update();
  } on Exception catch (ex, trace) {
    DialogView.showAlertDialog(msg: 'msg_TraitementImpossible'.tr);
    businessController.showDialogProgress(show: false);
    logError(ex, trace: trace, position: 'signInWithApple');
    signOut();
  } catch (ex, trace) {
    logError(ex, trace: trace, position: 'signInWithApple');
    signOut();
  }
  businessController.showDialogProgress(show: false);
}