signInWithApple method

Future<SocialLoginDataModel?> signInWithApple()

Implementation

Future<SocialLoginDataModel?> signInWithApple() async {
  try {
    var redirectURL =
        "https://SERVER_AS_PER_THE_DOCS.glitch.me/callbacks/sign_in_with_apple";
    var clientID = "AS_PER_THE_DOCS";
    var appleIdCredential = await SignInWithApple.getAppleIDCredential(
        scopes: [
          AppleIDAuthorizationScopes.email,
          AppleIDAuthorizationScopes.fullName,
        ],
        webAuthenticationOptions: WebAuthenticationOptions(
            clientId: clientID, redirectUri: Uri.parse(redirectURL)));

    final oAuthProvider = OAuthProvider('apple.com');

    final mcredential = oAuthProvider.credential(
      idToken: appleIdCredential.identityToken,
      accessToken: appleIdCredential.authorizationCode,
    );

    final userCredential =
        await FirebaseAuth.instance.signInWithCredential(mcredential);
    User? firebaseUser = userCredential.user;

    return SocialLoginDataModel(
        socialId: appleIdCredential.userIdentifier,
        firebaseAuthUser: firebaseUser,
        errorMessage: _successConst,
        status: true);
  } catch (e) {
    displayError(e);
    return SocialLoginDataModel(
        socialId: null,
        firebaseAuthUser: null,
        errorMessage: "${e.toString()}",
        status: false);
  }
}