appleLogin method

Future<Map<String, dynamic>> appleLogin()

Implementation

Future<Map<String, dynamic>> appleLogin() async {
  try {
    final appleCredential = await SignInWithApple.getAppleIDCredential(
      scopes: [
        AppleIDAuthorizationScopes.email,
        AppleIDAuthorizationScopes.fullName,
      ],
    );

    final oauthCredential = OAuthProvider("apple.com").credential(
      idToken: appleCredential.identityToken,
      accessToken: appleCredential.authorizationCode,
    );

    UserCredential userCredential =
        await FirebaseAuth.instance.signInWithCredential(oauthCredential);

    bool? isNewUser = userCredential.additionalUserInfo?.isNewUser;
    User? user = userCredential.user;

    if (user == null) return {'authenticated': false, 'isNewUser': false};

    dynamic data = await IvivaAccount().executeService('UXP.GoogleLogin', {
      'email': user.email!,
      'displayName': user.displayName ?? "",
      'photoUrl': user.photoURL ?? "",
    });

    await _authenticate(data[0]['apiKey']!);

    return {'authenticated': _authenticated, 'isNewUser': isNewUser ?? false};
  } catch (e) {
    return {'authenticated': false, 'isNewUser': false};
  }
}