diff --git a/LeStorage/Services.swift b/LeStorage/Services.swift index c29ba61..3148276 100644 --- a/LeStorage/Services.swift +++ b/LeStorage/Services.swift @@ -378,7 +378,7 @@ public class Services { request.httpMethod = HTTPMethod.get.rawValue request.setValue("application/json", forHTTPHeaderField: "Content-Type") - if self._isTokenRequired(type: T.self, method: apiCall.method) { + if self._isTokenRequired(type: T.self, method: apiCall.method), StoreCenter.main.isAuthenticated { let token = try self.keychainStore.getValue() request.addValue("Token \(token)", forHTTPHeaderField: "Authorization") } diff --git a/LeStorage/StoreCenter.swift b/LeStorage/StoreCenter.swift index f258f9f..1c59133 100644 --- a/LeStorage/StoreCenter.swift +++ b/LeStorage/StoreCenter.swift @@ -228,7 +228,8 @@ public class StoreCenter { } /// Returns whether the system has a user token - public func hasToken() -> Bool { + public var isAuthenticated: Bool { + guard self.userId != nil else { return false } do { _ = try self.service().keychainStore.getValue() return true @@ -485,8 +486,7 @@ public class StoreCenter { /// Basically asks the server for new content public func synchronizeLastUpdates() async throws { - let hasToken = try? self.service().hasToken() - guard hasToken == true else { + guard self.isAuthenticated else { return } diff --git a/LeStorage/Utils/KeychainStore.swift b/LeStorage/Utils/KeychainStore.swift index 7e650b6..99a3c00 100644 --- a/LeStorage/Utils/KeychainStore.swift +++ b/LeStorage/Utils/KeychainStore.swift @@ -1,6 +1,6 @@ // // KeychainStore.swift -// LeCountdown +// Padel Club (from Le Countdown) // // Created by Laurent Morvillier on 20/12/2023. //