Skip to content

Commit

Permalink
Expose isConnectedToProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
RuiAAPeres committed Aug 25, 2022
1 parent 5c806f2 commit 42598fa
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
Expand Up @@ -31,4 +31,5 @@ public enum Provider: String, Codable {
case eightSleep = "eight_sleep"
case withings = "withings"
case googleFit = "google_fit"
case hammerhead = "hammerhead"
}
14 changes: 10 additions & 4 deletions Sources/VitalCore/Core/Client/VitalClient.swift
Expand Up @@ -235,7 +235,6 @@ public class VitalClient {

await VitalClient.shared.userId.set(value: userId)


do {
try shared.secureStorage.set(value: userId, key: user_secureStorageKey)
}
Expand All @@ -245,16 +244,23 @@ public class VitalClient {
}
}

public func checkConnectedSource(for provider: Provider) async throws {
public func isUserConnected(to provider: Provider) async throws -> Bool {
let userId = await userId.get()
let storage = await configuration.get().storage

guard storage.isConnectedSourceStored(for: userId, with: provider) == false else {
return
return true
}

let connectedSources = try await self.user.userConnectedSources()
if connectedSources.contains(provider) == false {
return connectedSources.contains(provider)
}

public func checkConnectedSource(for provider: Provider) async throws {
let userId = await userId.get()
let storage = await configuration.get().storage

if try await isUserConnected(to: provider) == false {
try await self.link.createConnectedSource(userId, provider: provider)
}

Expand Down

0 comments on commit 42598fa

Please sign in to comment.