I hope that someone can help me. I have a SwiftUI Project and I use Firebase for the authentication (user login) in this app.
When my app starts my code looks like this:
import SwiftUI
import FirebaseAuth
import SimpleToast
struct HomeView: View {
@EnvironmentObject var authModel: AuthenticationModel
@EnvironmentObject var dashboardModel: DashboardModel
@EnvironmentObject var gameModel: GameModel
@State var userCode = ""
var body: some View {
if !authModel.loggedIn {
LaunchView()
.onAppear {
authModel.checkLogin()
}
} else {
TestView()
}
}
So the authModel.loggedIn is always false by default. And here is the code of my authModel.checkLogin() function:
func checkLogin() {
if UserService.shared.user.name == "" || UserService.shared.user.name == nil {
self.getUserInfoAfterLogin()
} else {
withAnimation {
self.loggedIn = Auth.auth().currentUser != nil ? true : false
}
}
}
This is the logic for checking if the user is already logged in or not by starting the app. This works fine as well. The problem is when the device is in an area with a bad network connection and the app is waiting 3-4 seconds for an answer of the Firebase server there is always my LaunchView() showed. I want to show some kind of ProgressView instead until the answer is given but also showing the LaunchView() when the user is not logged in. Is there a possibility to show another view when the app is waiting for the Firebase server to authenticate?