This commit is contained in:
2026-02-18 22:58:41 +01:00
parent b3db7cbd7b
commit 1ca76b0fec
5 changed files with 41 additions and 17 deletions

View File

@@ -198,7 +198,7 @@ extension Notification.Name {
struct TokenResponse: Codable {
let accessToken: String
let idToken: String
let idToken: String?
let tokenType: String
let expiresIn: Int?
let user: User

View File

@@ -60,10 +60,11 @@ actor APIClient {
}
if httpResponse.statusCode == 401 {
let message = try? decoder.decode(ErrorResponse.self, from: data).error
await MainActor.run {
AuthManager.shared.clearAuth()
}
throw NetworkError.unauthorized
throw NetworkError.httpError(statusCode: 401, message: message)
}
guard (200...299).contains(httpResponse.statusCode) else {
@@ -131,10 +132,11 @@ actor APIClient {
}
if httpResponse.statusCode == 401 {
let message = try? decoder.decode(ErrorResponse.self, from: data).error
await MainActor.run {
AuthManager.shared.clearAuth()
}
throw NetworkError.unauthorized
throw NetworkError.httpError(statusCode: 401, message: message)
}
guard (200...299).contains(httpResponse.statusCode) else {

View File

@@ -9,22 +9,22 @@ enum APIEndpoint {
static let me = "/auth/me"
// Clients
static let clients = "/api/clients"
static func client(id: String) -> String { "/api/clients/\(id)" }
static let clients = "/clients"
static func client(id: String) -> String { "/clients/\(id)" }
// Projects
static let projects = "/api/projects"
static func project(id: String) -> String { "/api/projects/\(id)" }
static let projects = "/projects"
static func project(id: String) -> String { "/projects/\(id)" }
// Time Entries
static let timeEntries = "/api/time-entries"
static let timeEntriesStatistics = "/api/time-entries/statistics"
static func timeEntry(id: String) -> String { "/api/time-entries/\(id)" }
static let timeEntries = "/time-entries"
static let timeEntriesStatistics = "/time-entries/statistics"
static func timeEntry(id: String) -> String { "/time-entries/\(id)" }
// Timer
static let timer = "/api/timer"
static let timerStart = "/api/timer/start"
static let timerStop = "/api/timer/stop"
static let timer = "/timer"
static let timerStart = "/timer/start"
static let timerStop = "/timer/stop"
}
struct APIEndpoints {