Monday, February 5, 2024
HomeiOS Developmentios - Firebase Auth indicators out everytime app relaunches - SwiftUI &...

ios – Firebase Auth indicators out everytime app relaunches – SwiftUI & Firebase


My app retains signing out each time I relaunch.

It used to run advantageous however since updating to Firebase 10.20.0 from >8.0.0 for VisionOS I’m operating into this concern.

appnameApp

@StateObject personal var retailer = Retailer()

init() {
    // Initialise Firebase
    FirebaseApp.configure()

}

var physique: some Scene {
    WindowGroup {
        ContentView()
            .environmentObject(retailer)
        }
    }
 }

ContentView

@EnvironmentObject var retailer: Retailer

swap retailer.userAuthState {
case .signedIn:
    AppTabView()
        .environmentObject(retailer)
    
case .signedOut:
    LoginView()
    
case .undefined:
    LoadingView()
    
}

enum UserAuthenticationState {
    case undefined, signedOut, signedIn
}

Retailer Object

class Retailer : ObservableObject {

personal var db = Firestore.firestore()

// Session Properties
@Printed var userAuthState: UserAuthenticationState = .signedOut

@Printed var session: Consumer?
@Printed var isEmailVerified = false
@Printed var userEmail: String?

init () {
    deal with = Auth.auth().addStateDidChangeListener { [self] (auth, person) in
        if let person = person {
            print("StateDidChangeListener")
            self.userEmail = person.e-mail
            self.session = person
            
            if let u = auth.currentUser {
                self.isEmailVerified = u.isEmailVerified
            }
            
            if self.profile == nil {
                self.fetchProfile(uid: person.uid)
            }
            
        } else {
            self.session = nil
            self.userAuthState = .signedOut
        }
    }
}

deinit {
    if let deal with = deal with {
        Auth.auth().removeStateDidChangeListener(deal with)
    }
}
}

Goal: VisionOS

SPM Model: 10.20.0



Supply hyperlink

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments