replace hasToken by a more robust isAuthenticated

sync2
Laurent 8 months ago
parent 6d8ce05dae
commit 6748c825df
  1. 2
      LeStorage/Services.swift
  2. 6
      LeStorage/StoreCenter.swift
  3. 2
      LeStorage/Utils/KeychainStore.swift

@ -378,7 +378,7 @@ public class Services {
request.httpMethod = HTTPMethod.get.rawValue request.httpMethod = HTTPMethod.get.rawValue
request.setValue("application/json", forHTTPHeaderField: "Content-Type") 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() let token = try self.keychainStore.getValue()
request.addValue("Token \(token)", forHTTPHeaderField: "Authorization") request.addValue("Token \(token)", forHTTPHeaderField: "Authorization")
} }

@ -228,7 +228,8 @@ public class StoreCenter {
} }
/// Returns whether the system has a user token /// Returns whether the system has a user token
public func hasToken() -> Bool { public var isAuthenticated: Bool {
guard self.userId != nil else { return false }
do { do {
_ = try self.service().keychainStore.getValue() _ = try self.service().keychainStore.getValue()
return true return true
@ -485,8 +486,7 @@ public class StoreCenter {
/// Basically asks the server for new content /// Basically asks the server for new content
public func synchronizeLastUpdates() async throws { public func synchronizeLastUpdates() async throws {
let hasToken = try? self.service().hasToken() guard self.isAuthenticated else {
guard hasToken == true else {
return return
} }

@ -1,6 +1,6 @@
// //
// KeychainStore.swift // KeychainStore.swift
// LeCountdown // Padel Club (from Le Countdown)
// //
// Created by Laurent Morvillier on 20/12/2023. // Created by Laurent Morvillier on 20/12/2023.
// //

Loading…
Cancel
Save