I’m trying to integrate Firebase authentication into my iOS app using Swift. I’ve set up the Firebase SDK and imported Firebase at the top of my Swift file, but I’m encountering an issue where the Auth
and User
classes from Firebase are not recognized in my code.
Here’s the relevant part of my code:
import Firebase
class AuthManager {
static let shared = AuthManager()
func loginUser(email: String, password: String, completion: @escaping (Result<User, Error>) -> Void) {
Auth.auth().signIn(withEmail: email, password: password) { authResult, error in
if let user = authResult?.user {
completion(.success(user))
} else if let error = error {
completion(.failure(error))
}
}
}
func registerUser(email: String, password: String, completion: @escaping (Result<User, Error>) -> Void) {
Auth.auth().createUser(withEmail: email, password: password) { authResult, error in
if let user = authResult?.user {
completion(.success(user))
} else if let error = error {
completion(.failure(error))
}
}
}
func signOutUser() {
do {
try Auth.auth().signOut()
} catch {
print("Error signing out: (error.localizedDescription)")
}
}
}
However, Xcode is giving me the following errors:
- "Cannot find ‘Auth’ in scope"
- "Cannot find type ‘User’ in scope"
I’ve already checked that I’ve properly imported Firebase at the top of my file, and I’ve integrated Firebase using CocoaPods according to the documentation. Is there something I’m missing or a step I overlooked in setting up Firebase authentication in my project?
Any help or suggestions would be greatly appreciated. Thank you!
2
Answers
I have added FirebaseAuth dependency in build phases it fixed it: –
If we look at the full view controller, there’s this line to import
Auth
:You’ll want to add that to your imports too.