I'm building an iOS app and need to allow my users to sign in with Google using XServer
I've downloaded and installed the SDK, created the OAuth credential on my Google Cloud Platform, and this is my code so far:
import GoogleSignIn
class GLogin: UIViewController, GIDSignInDelegate {
@IBOutlet weak var googleButton: UIButton!
var googleSignIn = GIDSignIn.sharedInstance()
// Google Sign in button
@IBAction func gSignInButton(_ sender: Any) {
googleSignIn?.presentingViewController = self
googleSignIn?.clientID = "My_Google_OAuth_Id"
googleSignIn?.delegate = self
googleSignIn?.signIn()
}
}
func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error!) {
guard let user = user else {
print("Google login cancelled.")
return
}
// Get User info
let password = user.userID ?? ""
let firstName = user.profile.givenName ?? ""
let lastName = user.profile.familyName ?? ""
let email = user.profile.email ?? password + "@google.com"
let profilePicURL = user.profile.imageURL(withDimension: 150)?.absoluteString
let username = firstName.lowercased() + lastName.lowercased()
let fullName = firstName + " " + lastName
self.XSSignUp(username: username, password: password, email: email, signInWith: "google") { (results, e) in
if error == nil {
// I don't know what to do here...
} else { DispatchQueue.main.async { print(e!) }
}}// ./ XSSignUp()
}
func sign(_ signIn: GIDSignIn!, didDisconnectWith user: GIDGoogleUser!, withError error: Error!) {
// Call your backend server to delete user's info after they requested to delete their account
}
So, I can successfully retrieve a Google user's data, as well as register the user in the database, but I don't know how to update its full name and profile picture, so those columns are empty after performing the code above.
What am I missing?