From 6748c825df353f11a317a3b1ae2e924a5160c63e Mon Sep 17 00:00:00 2001 From: Laurent Date: Wed, 19 Mar 2025 13:57:41 +0100 Subject: [PATCH] replace hasToken by a more robust isAuthenticated --- LeStorage/Services.swift | 2 +- LeStorage/StoreCenter.swift | 6 +++--- LeStorage/Utils/KeychainStore.swift | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) 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. //