How to always retrieve first name, last name and email via apple login?

173 views Asked by At

We are developing an app in flutter, and it uses apple login as one of the methods for signing into the app. When you first login via apple login, you are also asked to make a profile on our backend, where you enter some additional details about yourself. Some of those details include first name, last name and an email.

We now submitted the app for review to apple, and it got rejected, saying that when making a profile, fields for name, last name and email should be filled already from the apple sign in data. Fine. We did that. But, apple sign in sometimes returns null for this information - specificially, if user already used apple sign in for this app on this device.

Apple has now again rejected the app, even though it takes the data from apple login, and pre-fills it into the form. But, that data is not always available. For example, when users profile is deleted, and they try to make a new one, on the same device.

Apple appears to be testing on the same device as they did the first time, and the data is not being filled for them (this is visible from the screenshot that they send with the review).

Here is part of the code that we use to trigger apple sign in and then get the first name, last name and email.

final appleCredential = await SignInWithApple.getAppleIDCredential(
      scopes: [
        AppleIDAuthorizationScopes.email,
        AppleIDAuthorizationScopes.fullName,
      ],
    );

    final oAuthCredential = OAuthProvider('apple.com').credential(
      idToken: appleCredential.identityToken,
    );

    final UserCredential credentials = await FirebaseAuth.instance.signInWithCredential(oAuthCredential);

    String? email = appleCredential.email;
    String? name = appleCredential.givenName;
    String? surname = appleCredential.familyName;

    const storage = FlutterSecureStorage();

    // store email, first name and last name into flutter_secure_storage (since apple only returns this data when you first login via apple, and not on subsequent logins)
    if (email != null && name != null && surname != null) {
      storage.write(key: 'email', value: email);
      storage.write(key: 'first_name', value: name);
      storage.write(key: 'last_name', value: surname);
    } else {
      email = email ?? (await storage.read(key: 'email'));
      name = name ?? (await storage.read(key: 'first_name'));
      surname = surname ?? (await storage.read(key: 'last_name'));
    }


// after this, we either log the user into the app, or redirect to register screen

As you can see, we even save the data into the flutter secure storage, so we can retrieve it later. But, if the app is deleted and then new version installed, this is of course also cleared.

We have added a note when submitting the app for review, to please delete the app fully first, and clear apple sign in by clicking on: "Settings -> password & security -> Sign in with Apple -> [our app] -> Stop using apple ID", but the app was still rejected for same reason, with screenshot again attached to the rejection, where data is not filled in.

But, what can we do if apple doesnt return the data in some cases? How can we get the app through the review process?

0

There are 0 answers