Hey everyone,
I’m having an issue with my login. Hopefully this is clear. (I’ve read the related posts and tried to implement the suggested changes, but I am encountering 2 issues:
- if I create my code exactly as Chris has instructed, I get an empty login screen after tapping on the login button. 2) if I add the FUIEmailAuth code, I get an error "Use of unresolved identifier ‘FUIEmailAuth’
I’ve added the FirebaseUI/Email pod, I import the FirebaseAuth, but that hasn’t helped.
I’m not sure what to do next…
//
// LoginViewController.swift
// Photo App
//
// Created by Mike Nelson on 1/25/20.
// Copyright © 2020 CIC Solutions. All rights reserved.
//
import UIKit
import FirebaseAuth
import FirebaseUI
class LoginViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
@IBAction func loginTapped(_ sender: UIButton) {
// Create Firebase Auth UI object
let authUI = FUIAuth.defaultAuthUI()
// Check that it isn't nil
//if let authUI = authUI {
guard authUI != nil else{
return
}
// Set the login view controller as the delegate
authUI?.delegate = self
authUI?.providers = [FUIEmailAuth()] <`*--- HERE IS where the error comes in*`
// Create a Firebase auth pre build UI view controller
let authViewController = authUI!.authViewController()
// Present it
present(authViewController, animated: true, completion: nil)
// }
}
}
extension LoginViewController: FUIAuthDelegate {
func authUI(_ authUI: FUIAuth, didSignInWith authDataResult: AuthDataResult?, error: Error?) {
// Check if an error occurred
guard error == nil else {
print("an error has happened")
return
}
// Get the user
let user = authDataResult?.user
// Check if user is nil
if let user = user {
// this means that we have a user, now check if they have a profile
UserService.getUserProfile(userID: user.uid) { (u) in
if u == nil {
// No profile, go to Profile Controller
self.performSegue(withIdentifier: Constants.Segue.profileViewController, sender: self)
}
else {
// This user has a profile go to Tab Controller
let tabBarVC = self.storyboard?.instantiateViewController(withIdentifier: Constants.Storyboard.tabBarController)
self.view.window?.rootViewController = tabBarVC
self.view.window?.makeKeyAndVisible()
}
}
}
}
}