This is my sign-in with Apple function
signInWithApple(Ref ref) async {
try {
final FirebaseAuth auth = FirebaseAuth.instance;
final AuthorizationCredentialAppleID appleCredential =
await SignInWithApple.getAppleIDCredential(
scopes: [
AppleIDAuthorizationScopes.email,
AppleIDAuthorizationScopes.fullName
],
webAuthenticationOptions: WebAuthenticationOptions(
clientId: 'clientId',
redirectUri: Uri.parse('uri'),
),
);
final OAuthProvider oAuthProvider = OAuthProvider('apple.com');
final credential = oAuthProvider.credential(
idToken: appleCredential.identityToken,
accessToken: appleCredential.authorizationCode);
final User? user = (await auth.signInWithCredential(credential)).user;
if (user?.email != null) {
ref
.read(authProvider.notifier)
.setAppleEmailToRegistration(user!.email!);
final Either<CleanFailure, EmailLoginSecondStepResponse> data =
await api.post(
fromData: (json) => EmailLoginSecondStepResponse.fromMap(json),
endPoint: APIRoute.socialLogin,
body: {"email": user.email},
withToken: false,
);
return data;
} else {
return left(
CleanFailure.withData(
tag: "Apple sign-in error",
url: "apple.com",
method: "POST",
statusCode: 000,
header: const {},
body: const {},
error: const CleanError(
message: "Apple sign-in error",
),
),
);
}
} catch (e) {
Logger.e("Apple sign in error: $e");
return left(
CleanFailure.withData(
tag: "Apple sign-in error",
url: "apple.com",
method: "POST",
statusCode: 000,
header: const {},
body: const {},
error: CleanError(
message: e.toString(),
),
),
);
}
}
The issue lies in retrieving the full name from Apple credentials. Currently, only the email is accessible. However, the full name is obtained only upon the user's re-login to their Apple account. If an Apple account remains logged in on the device, the name field returns null.
Can anyone help me to fix this?
Please try to implementing this code to solve your error.