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.