Learn Courses My Dashboard

Issue with Firebase Authentication

Hi everyone, I am having an issue in the iOS Databases course, Module 3, Lesson 2. ( I am using Xcode 13.4 )
The problem is with the note under that video saying that at timestamp 8:45 I should import FirebaseEmailAuthUI instead of FirebaseUI, when I try to do this I get an error saying that there is no such module.

I also noticed that firebase works with libraries or SDK’s that I have to add in the package dependencies instead of adding pods in a pod file using cocoa pods.

I don’t know if this is the cause but because of this I can only add the FirebaseAuth SDK and not all the other pods shown in that lesson.

Does anyone know how I can add those other pods or how to fix my error?

One of the problems with Firebase is that the Developers of that software update and change things relatively often and that is sometimes very frustrating especially when the changes means that the tutorial is then broken.

The documentation for the Drop in Auth UI seems to be a bit sketchy.

https://firebase.google.com/docs/auth/ios/firebaseui

I’m not sure what import command you would need to use at the moment though it seems that the documentation is saying to use:

import FirebaseAuthUI

Thanks for your reply.

I have tried to use:
import FirebbaseAuthUI
But I get the same error saying that there is no such module as: FirebaseAuthUI

These are the only modules I can use:

@Pixel

Hi Rune,

I wish I had an answer but unfortunately I don’t. Perhaps @joash might be able to shed some light on what the solution might be.

I believe you should just use FirebaseAuth, unfortunately I think their documentation is out of date

@Chris_Parker

Hi Chris,
No problem, thanks for your help anyway.

I thought that at first too, but when I watch a little bit further in the video and add the code, I get an error saying it doesn’t recognize that code.

Typically that means it’s been depreciated, Firebase changes their code a lot.

The Firebase code you can google that and see if you can find the updated version of the code.

Which line specifically says it doesn’t exist?

Hi @Pixel

Are you using a repository for your project?

or is there a chance we can take a look at your code? if you have a repo for this can project of yours, can you add me as a contributor? or send a link here? My username is emptybasket on github. :slight_smile:

you can also copy and paste your code also here.

Hi @joash

I hope this helps you.
This is the file where I get an error:

//
//  LoginForm.swift
//  Firebase Auth Demo
//
//  Created by Rune Pollet on 21/05/2022.
//

import Foundation
import SwiftUI
// I can't import FirebaseAuthUI here
import FirebaseAuth

struct LoginForm: UIViewControllerRepresentable {
    
    func makeUIViewController(context: Context) -> UINavigationController {
        
        // This is a line of code that is added first in the lesson but it doesn't recognize it...
        let authUI = FUIAuth.defaultAuthUI()
        
        return UINavigationController()
    }
    
    func updateUIViewController(_ uiViewController: UINavigationController, context: Context) {
        
    }
    
}

Hi again,
is there any chance this code gives a clue on what I need to fix or how to fix it? Or do you have suggestions where I can search for a solution.
Bit stuck here unfortunately.

Thanks!

Does this doc help?

I have looked at it but it doesn’t seem to work for me either.

@Pixel

Hi Rune,

OK, I have just been messing around with the UIKit version of this “Drop-In Auth UI” and in that version the Firebase frameworks have been added using cocoapods. You wont get access to the right frameworks using Swift Package Manager for the reasons I mentioned in my last post.

So, if you want to have a crack at getting the SwiftUI version going (FirebaseAuthDemo) using cocoapods you will have to have the following pods specified in your Podfile:

    pod 'Firebase/Auth'
    pod 'FirebaseUI/Auth'
    pod 'FirebaseUI/Email'

This is my ContentView (Note the import statement is different):

import SwiftUI
import FirebaseEmailAuthUI

struct ContentView: View {
    @Binding var loggedIn: Bool
    
    var body: some View {
        VStack {
            Text("Welcome")
            Button(action: {
                try! FUIAuth.defaultAuthUI()?.signOut()
                loggedIn = false
            }) {
                Text("Sign Out")
            }
        }
    }
}

My LaunchView (Also note the import statement):

import SwiftUI
import FirebaseEmailAuthUI

struct LaunchView: View {
    @State private var loggedIn = false
    @State private var showLoginForm = false

    var body: some View {
        if !loggedIn {
            Button {
                showLoginForm = true
            } label: {
                Text("Sign In")
            }
            .sheet(isPresented: $showLoginForm, onDismiss: checkLogin) {
                LoginForm()
            }
            .onAppear {
                checkLogin()
            }
        } else {
            ContentView(loggedIn: $loggedIn)
        }
    }

    func checkLogin() {
        loggedIn = FUIAuth.defaultAuthUI()?.auth?.currentUser != nil ? true : false
    }
}

My LoginForm (Again, the import statement):

import Foundation
import SwiftUI
import FirebaseEmailAuthUI

struct LoginForm: UIViewControllerRepresentable {

    func makeUIViewController(context: Context) -> UINavigationController {

        let authUI = FUIAuth.defaultAuthUI()
        guard authUI != nil else {
            return UINavigationController()
        }

        let providers = [FUIEmailAuth()]
        authUI!.providers = providers

        return authUI!.authViewController()
    }

    func updateUIViewController(_ uiViewController: UINavigationController, context: Context) {

    }
}

Don’t forget to add your GoogleService-Info.plist file and make sure it is named EXACTLY as:

GoogleService-Info.plist

Let me know how you go.

Hello, @Pixel can you share what’s inside your Podfile?

You should see similar to this.

I tried running the project file for the iOS Databases course, Module 3, Lesson 2 and it worked without issues on my side.

Hi @Chris_Parker,

I have added those pods in my pod file and I used the .xcworkspace file instead of my original .xcodeproj file.
When I wrote import FirebaseEmailAuthUI and ran the project it all worked!

Thank you so much for thinking with me and helping me out, I actually don’t know why this worked so could you explain it to me so I could maybe learn from it?

Hi @joash,

So this is currently my pod file and it is working now:

Also thank you for thinking along with me.

I’m guessing that the reason it was not working in the first place was because you were opening the project using the xcodeproj file rather than the xcworkspace file.

During the pod installation process the xcworkspace file is created and from then on the project must be opened in Xcode using that file.

Same observation with @Chris_Parker, have you try opening the project using Firebase Auth Demo.xcworkspace? the one lighted on the image provided below?

Yes, I have and it works now.

1 Like