HomeiOS Developmentios - The way to fetch consumer information from firebase

ios – The way to fetch consumer information from firebase


I’m making an attempt to determine the best way to fetch consumer information I’ve tried utilizing this code however nothing is altering when my web page replace I am undecided the best way to write this code to get my consumer information I’ve obtain no errors What am I lacking from this code that may permit me to fetch that information from firebase to look on my display screen ?

I’ve the consumer picture and username saved in firestore beneath ProfileImages in collections how do write this code to fetch that information and consider that information.

@major
struct Tunnel_VisionApp: App {
    @StateObject var userDataHere = UserDataFile()
  
  @UIApplicationDelegateAdaptor(AppDelegate.self) var delegate



  var physique: some Scene {
    WindowGroup {
      NavigationView {
        SignUpView()
          ProfileHeader()
              .environmentObject(userDataHere)
            .onAppear {userDataHere.fetchUser()}
      }
class UserDataFile: ObservableObject {
  
    @Printed var customers = [User]()
    
    func fetchUser() {

       if Auth.auth().currentUser != nil {

         let db = Firestore.firestore()
         let docRef = db.assortment("consumer").doc("ProfileImages")

         docRef.getDocument { (doc, error) in
             if let doc = doc, doc.exists {
                 let dataDescription = doc.information().map(String.init(describing:)) ?? "nil"
                 print("Doc information: (dataDescription)")
             } else {
                 print("Doc doesn't exist")
             }
         }
struct SignUpView: View {
 var physique: some View {
  Button {
        Register()
       fetchUser()
        showModal = true
    }label: {
        HStack {
            Spacer()
            
            Textual content(isLoginMode ? "Log In" : "Create Account").padding(.vertical, 10)
                .font(.system(dimension: 14, weight: .semibold))                     .foregroundColor(.white)
        
                .environmentObject(userDataHere)
              .onAppear {userDataHere.fetchUser()}

   func fetchUser() {
       let deal with = Auth.auth().addStateDidChangeListener { auth, consumer in
          // ...
        
       let consumer = Auth.auth().currentUser
        if let consumer = consumer {
      
          let uid = consumer.uid
          let e mail = consumer.e mail

              let db = Firestore.firestore()
              let docRef = db.assortment("consumer").doc("ProfileImages")

              docRef.getDocument { (doc, error) in
                  if let doc = doc, doc.exists {
                      let dataDescription = doc.information().map(String.init(describing:)) ?? "nil"
                      print("Doc information: (dataDescription)")
                  } else {
                      print("Doc doesn't exist")
                  }
 struct ProfileHeader: View {
        
        @StateObject var userDataHere = UserDataFile()
 var physique: some View {

 Button {

        }label: {
            NavigationLink(vacation spot: AccountView()) {
                Textual content("Account")
                
                
                    .foregroundColor(.white)
                    .environmentObject(userDataHere)
                  .onAppear {userDataHere.fetchUser()}
                   
            }

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments