Network request using Combine framework

I’m building an ios app using SwiftUI and Combine framework.
I’m handling my login in a class called TokenService which handles the API request, then I call methods of this class in my LoginViewModel (which is an ObservableObject).
So how do you think should I update my @Published values in the TokenService (which are isLoggedIn, isLoading, errorMessage)?
I appreciate the help.

Here’s my code:

import Foundation
import Combine

class TokenService {
    func validateLogin(email: String, password: String) {
        let url = URL(string: "\(baseURL)/users.json")!
        var request = URLRequest(url: url)
            request.httpBody = try ["username":email,"password":password], options: .prettyPrinted)
        } catch {
        request.httpMethod = "POST"
        URLSession.shared.dataTask(with: request) { (data, response, error) in
            if error != nil { return }
            guard let httpResponse = response as? HTTPURLResponse, httpResponse.statusCode == 200 else { return }
            guard let data = data else { return }
                let parsedData = try JSONDecoder().decode(LoginData.self, from: data)
                DispatchQueue.main.async {
                    // ??
            } catch {

struct LoginData: Decodable{
    var access:String = ""
    var refresh:String = ""
    let id:String = ""

Hey Alireza, I’ll have to defer to someone else who might know.
Once i get caught up with the Combine framework myself, i’ll be able to comment :stuck_out_tongue:
Meanwhile, try asking Mark Moeykens and Paul Hudson as they’re pretty deep into the Combine framework stuff.