Back

[SOLVED] Flutter Login with Apple

  • 0
  • Users
  • Flutter
  • Accounts
yannic
21 Mar, 2023, 12:35

I use the following code in flutter for the session creation for the login with apple:

TypeScript
    try {
      final response = await account.createOAuth2Session(
        provider: 'apple',
        success: "https://XX.com/auth/oauth2/success",
        failure: "https://XX.com/auth/oauth2/failure",
      );
      print(response);
      return response;
    } on AppwriteException {
      rethrow;
    }
  }````

To open the login page I use:
```ElevatedButton(
                    child: const Text('Login with Apple'),
                    onPressed: () async {
                      await AuthHelper().loginWithApple().then((value) {
                        prefs.setSessionId(value.$id);

                        Navigator.of(context).pushReplacement(
                          MaterialPageRoute(
                            builder: (context) => const HomePage(),
                          ),
                        );
                      }).onError((error, stackTrace) {
                        print(error);
                      });
                    },
                  ),````

In the simulator I get the error seen in the screenshot. When I run the app on my iPhone with the cable connected the page opens fine, but when I click on login I get the error that the login is not possible ("registration not completed"). I host appwrite on digitalocean with a custom (sub-)domain.
TL;DR
The issue was with mismatched Service ID and Bundle ID in Appwrite. The solution is to ensure they match. The domain and redirect URI for Appwrite should be: - Domain: Your Appwrite domain - Redirect URI: `https://[DOMAIN]/v1/account/sessions/oauth2/callback/apple/[PROJECT ID]` The success and failure URLs are unrelated to the error. Make sure to follow the tutorial mentioned in the thread for Apple Sign-In with Appwrite. The code for session creation and login with Apple in Flutter was also provided.
Drake
21 Mar, 2023, 16:43

This typically happens because of some mismatch between what was entered into Appwrite for the OAuth2 and Appwrite. This might help: https://dev.to/appwrite/apple-sign-in-with-appwrite-2576

yannic
21 Mar, 2023, 20:07

Yeah I used this tutorial but it didn’t work.

yannic
21 Mar, 2023, 20:09

Maybe you can tell me what domain and redirect uri I should add? The redirect uri should be the one from the appwrite Formular? And the domain just the domain from the appwrite instance. But it doesn’t work for me this way. Nothing comes back. Do I have to modify the success and failure URLs?

Drake
21 Mar, 2023, 20:11

i've followed the tutorial before so it should work 🧐

Drake
21 Mar, 2023, 20:16

Maybe you can tell me what domain and redirect uri I should add?

The domain should be your appwrite domain. the redirect url should be something like:

TypeScript
https://[DOMAIN]/v1/account/sessions/oauth2/callback/apple/[PROJECT ID]

Do I have to modify the success and failure URLs? These are unrelated to the error you're getting.

Make sure your Service ID in Apple matches the Bundle ID you put in Appwrite.

yannic
22 Mar, 2023, 10:22

Yeah the problem was with the Service ID that has to match the Bundle ID in Appwrite. Thanks a lot!

yannic
22 Mar, 2023, 10:22

[SOLVED] Flutter Login with Apple

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more