Flutter And Firebase Sign in With apple
Appstore requires an Apple Flutter And Firebase Sign in With apple feature if your app has Facebook, google, or any other third-party login in the app. The easiest way to implement this is using Firebase. Firebase is a widely used BAAS with flutter.
Pre Requisites
- Apple Developer Account
- XCode 15
- An iOS 15.x Simulator Signed in with Apple
Firebase Configuration
First, we must enable “Apple Sign in” in the Firebase console.
Configure Flutter And Firebase Sign in With apple on Apple Developer Site
To let the user sign in with Apple, we must first configure it on Apple Developer’s site.
Configure XCode
After enabling it, we also need to add the capability in the code.
Code Implementation
We are all done with the boring part and are ready to write the code, the fun part.
First, add the following dependency in your pubspec.yaml
dependencies:
firebase_core: ^2.15.1
firebase_auth: ^4.7.3
Once dependency is added, we will write the function for Apple Sign-In.
import 'package:firebase_auth/firebase_auth.dart';
Future<bool> signInWithApple() async {
final appleProvider = AppleAuthProvider();
final userCredential = await FirebaseAuth.instance.signInWithProvider(appleProvider);
return userCredential.user == null ? false : true;
}
The above functions create the AppleAuthProvider instance, which is then passed to signInWithProvider, which lets the user sign in with native authentication flow for the respective provider.
This will pop up the Login Flow for Apple, and once the user enters the credentials, we are checking for the user. If the returned user is null, it means the user login failed otherwise, the login is successful.
Now, let’s call this function on button click. We will use a simple Elevated Button to call the above function on onPressed event.
ElevatedButton(
onPressed: signInWithApple,
child: const Text('Sign In With Apple'),
),
Hurray! We are done with Apple Login using Firebase.
Conclusion
In this article, we have covered the Apple sign-in with Flutter using Firebase as it is a requirement by ios nowadays if you have integrated third-party login. Hope you will find it helpful.
Thank you for reading and Have a great day.