Created
          January 21, 2021 15:08 
        
      - 
      
- 
        Save emiliodallatorre/2c39cd4a28fe8478021e52505ea8433d to your computer and use it in GitHub Desktop. 
    Funzione per il login con Apple
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | static Future<UserModel> signInWithApple() async { | |
| final OAuthProvider appleOAuth = OAuthProvider("apple.com"); | |
| final AuthorizationCredentialAppleID appleCredential = await SignInWithApple.getAppleIDCredential( | |
| scopes: [ | |
| AppleIDAuthorizationScopes.email, | |
| AppleIDAuthorizationScopes.fullName, | |
| ], | |
| ); | |
| OAuthCredential appleRemappedCredential = appleOAuth.credential(idToken: appleCredential.identityToken, accessToken: appleCredential.authorizationCode); | |
| UserCredential result = await FirebaseAuth.instance.signInWithCredential(appleRemappedCredential); | |
| if (result.user != null) { | |
| // debugPrint(result.user.uid); | |
| if ((await References.usersCollection.doc(result.user.uid).get()).exists) return UserModel.fromJson((await References.usersCollection.doc(result.user.uid).get()).data()); | |
| while (!(await References.usersCollection.doc(result.user.uid).get()).exists) await Future.delayed(Duration(seconds: 2)); | |
| UserModel currentUser = UserModel.fromJson((await References.usersCollection.doc(result.user.uid).get()).data()); | |
| currentUser.reference = References.usersCollection.doc(result.user.uid); | |
| currentUser.displayName = appleCredential.givenName + " " + appleCredential.familyName; | |
| await result.user.updateProfile(displayName: appleCredential.givenName + " " + appleCredential.familyName); | |
| await currentUser.updateOnServer(); | |
| return currentUser; | |
| } | |
| throw ("Errore nel login con Apple!"); | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment