My Env
Firebase support guy told me to fill this issue here:
Thank for your patience. After checking this issue further with the team, it was brought to my attention that this issue could happen to other developers. In order for the appropriate team to provide you more information on this and at the same time help the community in case they are struggling with this issue, we will need you to open a new issue in the Firebase UI issue tracker.
I am using FirebaseUI Auth in my app and now I want to start to use Firebase Invites. Firebase Invites for iOS only works for users who signed in with a Google account.
The problem is when a user closes and reopens the app. It seems that google authentication context is not set anymore causing impossibility to open the firebase invites screen .
These steps works:
1 - User opens the app.
2 - User signed in with google account
3 - Firebase Invitation Screen opens as expected.
These steps makes Firebase Invites stoping working
1 - User open the app.
2 - Firebase Auth knows that this is a returning user. The user is signned in automatically.
3 - Firebase Invitation Screen can't be open.
Possible solution:
In some moment firebase ui auth needs to call GIDSignIn.sharedInstance().signInSilently() to reauthenticate the google user.
Is there any workaround?
Thank You
@rodrigosol We will discuss internally this functionality.
As a workaround please add next code before opening invitation:
import GoogleSignIn
...
GIDSignIn.sharedInstance().clientID = FirebaseApp.app()?.options.clientID
GIDSignIn.sharedInstance().scopes = ["https://www.googleapis.com/auth/userinfo.email", "https://www.googleapis.com/auth/userinfo.profile"] // or use Exactly the same scopes as you were using for Google provider configuration. Here I've used default values.
GIDSignIn.sharedInstance().signInSilently()
@yramanchuk thanks for the workaround. It worked!
Here's a more robust handling of the problem
@IBAction func inviteTapped(_ sender: Any) {
GIDSignIn.sharedInstance().clientID = FirebaseApp.app()?.options.clientID
GIDSignIn.sharedInstance().scopes = ["https://www.googleapis.com/auth/userinfo.email", "https://www.googleapis.com/auth/userinfo.profile"]
GIDSignIn.sharedInstance().uiDelegate = self
GIDSignIn.sharedInstance().delegate = self
GIDSignIn.sharedInstance().signInSilently()
}
func inviteFinished(withInvitations invitationIds: [String], error: Error?) {
if let error = error {
print("Failed: \(error.localizedDescription)")
} else {
print("\(invitationIds.count) invites sent")
}
}
func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error!) {
switch error {
case .some(let error as NSError) where error.code == GIDSignInErrorCode.hasNoAuthInKeychain.rawValue:
GIDSignIn.sharedInstance().signIn()
case .some(let error):
print("Login error: \(error.localizedDescription)")
case .none:
if let invite = Invites.inviteDialog() {
invite.setInviteDelegate(self)
// NOTE: You must have the App Store ID set in your developer console project
// in order for invitations to successfully be sent.
// A message hint for the dialog. Note this manifests differently depending on the
// received invitation type. For example, in an email invite this appears as the subject.
invite.setMessage("Try this out!\n -\(Auth.auth().currentUser!.displayName ?? "")")
// Title for the dialog, this is what the user sees before sending the invites.
invite.setTitle("Invites Example")
invite.setDeepLink("app_url")
invite.setCallToActionText("Install!")
invite.open()
}
}
}
Most helpful comment
Here's a more robust handling of the problem