title: Swiftui - Fetch data after login
body: <p>I'm starting to learn SwiftUI and i'm looking for better solution to fetch user data after successful login.</p>
  <p>For example, i need to see if the user has the account blocked or not after login</p>
  <p>For this i have create struct in Users.swift</p>
  <pre><code>struct Users: Identifiable, Codable{
  
      @DocumentID var id: String?
      var Societe : String
      var Nom : String
      var Prenom : String
      var HasBlocked : Bool
      var SiteID : [String]
      var Poste : String
      var Email : String
  }
  </code></pre>
  <p>and firebase class in Firebase.swift</p>
  <pre><code>class Firebase: ObservableObject {
      
      @EnvironmentObject var viewRouter: ViewRouter
      @Published var user : Users? = nil
  
      private var db = Firestore.firestore()
      
      
          func fetchData() {
              db.collection(&quot;Users&quot;).document(Auth.auth().currentUser!.uid).addSnapshotListener{ (snapshot, error) in
                  guard let documents = snapshot?.data() else {
                      print(&quot;No documents&quot;)
                      return
                  }
                  let name = documents[&quot;Nom&quot;] as? String ?? &quot;&quot;
                  let surname = documents[&quot;Prenom&quot;] as? String ?? &quot;&quot;
                  let email = documents[&quot;Email&quot;] as? String ?? &quot;&quot;
                  let societe = documents[&quot;Societe&quot;] as? String ?? &quot;&quot;
                  let poste = documents[&quot;Poste&quot;] as? String ?? &quot;&quot;
                  let siteId = documents[&quot;SiteID&quot;] as? [String] ?? []
                  let hasBlocked = documents[&quot;HasBlocked&quot;] as? Bool ?? true
                  
                  if let user = self.user?.SiteID{
                      print(user)
                  }else{
                      print(&quot;no document2&quot;)
                  }
                  
                  self.user = Users(Societe: societe, Nom: name, Prenom: surname, HasBlocked: hasBlocked, SiteID: siteId, Poste: poste, Email: email)
                  }
          }
  }
  </code></pre>
  <p>and in the SignInView after press login button, i call func signInUser</p>
  <pre><code>
  @ObservedObject private var firebase = Firebase()
  
  func signInUser(userEmail: String, userPassword: String) {
          
          signInProcessing = true
          
          Auth.auth().signIn(withEmail: email, password: password) { authResult, error in
          
              guard error == nil else {
                  signInProcessing = false
                  signInErrorMessage = error!.localizedDescription
                  return
              }
              switch authResult {
              case .none:
                  print(&quot;Could not sign in user.&quot;)
                  signInProcessing = false
              case .some(_):
                  print(&quot;User signed in&quot;)
  
                  // get data and check ??
  
                  signInProcessing = false
                  withAnimation {
                      viewRouter.currentPage = .homePage
                  }
              }
          }
      }
  </code></pre>
  <p>But i don't know how to fetch data after login for check if the account has blocked and then pass the data to Homeview without re-fetch data to optimize call database.</p>
  <p>thank for your help</p>