signInWithApple method
Signs in using Apple authentication.
Implementation
@override
Future<Either<AuthFailure, ExaAuthUser?>> signInWithApple(
{required String clientId}) async {
try {
final rawNonce = generateNonce();
final nonce = _sha256ofString(rawNonce);
AuthorizationCredentialAppleID? appleIdCredential;
try {
final currentUser = firebaseAuth.currentUser;
await currentUser?.delete();
appleIdCredential = await SignInWithApple.getAppleIDCredential(
nonce: nonce,
scopes: [
AppleIDAuthorizationScopes.email,
AppleIDAuthorizationScopes.fullName,
],
);
} catch (e) {
return left(_resolveException(
exception: null,
stackTrace: null,
locale: 'getAppleIDCredential',
sigInType: SigInType.apple));
}
final oauthCredential = OAuthProvider('apple.com').credential(
rawNonce: rawNonce,
idToken: appleIdCredential.identityToken,
);
if (ExaAuth.onlyCredential) {
return right(ExaAuthUser.withCredential(
credential: oauthCredential,
rawNonce: rawNonce,
idToken: appleIdCredential.identityToken,
));
} else {
final userCredential = await _signInWithCredential(oauthCredential);
return right(_resolveUser(firebaseUser: userCredential.user));
}
} catch (exception, stackTrace) {
return left(_resolveException(
exception: exception,
stackTrace: stackTrace,
locale: 'signInWithApple',
sigInType: SigInType.apple));
}
}