           text: $email, placeholder: "Email", symbolName: "person.circle.fill"
         )
 
-        CustomStyledButton(title: "Send Sign In Link") {
-          sendSignInLink()
-        }
-        .disabled(email.isEmpty)
+        CustomStyledButton(title: "Send Sign In Link", action: sendSignInLink)
+          .disabled(email.isEmpty)
 
         Spacer()
       }
       .padding()
       .navigationBarTitle("Passwordless Login")
     }
-    .onOpenURL { (url) in
+    .onOpenURL { url in
       let link = url.absoluteString
       if Auth.auth().isSignIn(withEmailLink: link) {
-        passwordlessSignIn(email: email, link: link) { user, error in
-          isPresentingSheet = user?.isEmailVerified ?? false
+        passwordlessSignIn(email: email, link: link) { result in
+          switch result {
+          case let .success(user):
+            isPresentingSheet = user?.isEmailVerified ?? false
+          case .failure:
+            isPresentingSheet = false
+          }
         }
       }
     }
     .sheet(isPresented: $isPresentingSheet) {
-      SuccessView(email: $email)
+      SuccessView(email: email)
     }
   }
 

}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
      ContentView()
    }
}

// MARK: Example Auth View Modifier

extension View {
  func handlePasswordlessLogin(forEmail email: String,
                               completion: @escaping (_ user: User?, _ error: Error?) -> ()) -> some View {
      self.onOpenURL { (url) in
        let link = url.absoluteString
        if Auth.auth().isSignIn(withEmailLink: link) {
          Auth.auth().signIn(withEmail: email, link: link) { result, error in
            print(error ?? "Authentication was successful.")
            let newUser = error == nil ? Auth.auth().currentUser : nil
            completion(newUser, error)
          }
        }
      }
    }
}


  }

  private func passwordlessSignIn(email: String, link: String,
                                  completion: @escaping (Result<User?, Error>) -> Void) {
    Auth.auth().signIn(withEmail: email, link: link) { result, error in
      if let error = error {
        print("ⓧ Authentication error: \(error.localizedDescription).")
        completion(.failure(error))
      } else {
        print("✔ Authentication was successful.")
        completion(.success(Auth.auth().currentUser))
      }
    }
  }
}
