From 7a2a324b2384bb37dfd2d18265a41569c68a598c Mon Sep 17 00:00:00 2001 From: Konstantin Wohlwend Date: Tue, 20 Jan 2026 15:32:33 -0800 Subject: [PATCH] Fix build --- .../Sources/StackAuth/StackClientApp.swift | 41 +++++++++++++++++++ .../swift/Sources/StackAuth/TokenStore.swift | 9 +++- 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/sdks/implementations/swift/Sources/StackAuth/StackClientApp.swift b/sdks/implementations/swift/Sources/StackAuth/StackClientApp.swift index 83947aef8..9f05a2c53 100644 --- a/sdks/implementations/swift/Sources/StackAuth/StackClientApp.swift +++ b/sdks/implementations/swift/Sources/StackAuth/StackClientApp.swift @@ -86,6 +86,7 @@ public actor StackClientApp { let client: APIClient private let baseUrl: String + #if canImport(Security) public init( projectId: String, publishableClientKey: String, @@ -126,6 +127,46 @@ public actor StackClientApp { } } } + #else + public init( + projectId: String, + publishableClientKey: String, + baseUrl: String = "https://api.stack-auth.com", + tokenStore: TokenStore = .memory, + urls: HandlerUrls = HandlerUrls(), + noAutomaticPrefetch: Bool = false + ) { + self.projectId = projectId + self.baseUrl = baseUrl + self.urls = urls + + let store: any TokenStoreProtocol + switch tokenStore { + case .memory: + store = MemoryTokenStore() + case .explicit(let accessToken, let refreshToken): + store = ExplicitTokenStore(accessToken: accessToken, refreshToken: refreshToken) + case .none: + store = NullTokenStore() + case .custom(let customStore): + store = customStore + } + + self.client = APIClient( + baseUrl: baseUrl, + projectId: projectId, + publishableClientKey: publishableClientKey, + tokenStore: store + ) + + // Prefetch project info + if !noAutomaticPrefetch { + Task { + _ = try? await self.getProject() + } + } + } + #endif // MARK: - OAuth diff --git a/sdks/implementations/swift/Sources/StackAuth/TokenStore.swift b/sdks/implementations/swift/Sources/StackAuth/TokenStore.swift index f3cbe5d3b..ff36a6c15 100644 --- a/sdks/implementations/swift/Sources/StackAuth/TokenStore.swift +++ b/sdks/implementations/swift/Sources/StackAuth/TokenStore.swift @@ -1,5 +1,7 @@ import Foundation +#if canImport(Security) import Security +#endif /// Protocol for custom token storage implementations public protocol TokenStoreProtocol: Sendable { @@ -11,8 +13,11 @@ public protocol TokenStoreProtocol: Sendable { /// Token storage configuration public enum TokenStore: Sendable { + #if canImport(Security) /// Store tokens in Keychain (default, secure, persists across launches) + /// Only available on Apple platforms (iOS, macOS, etc.) case keychain + #endif /// Store tokens in memory (lost on app restart) case memory @@ -27,8 +32,9 @@ public enum TokenStore: Sendable { case custom(any TokenStoreProtocol) } -// MARK: - Keychain Token Store +// MARK: - Keychain Token Store (Apple platforms only) +#if canImport(Security) actor KeychainTokenStore: TokenStoreProtocol { private let projectId: String private let accessTokenKey: String @@ -126,6 +132,7 @@ actor KeychainTokenStore: TokenStoreProtocol { SecItemDelete(query as CFDictionary) } } +#endif // MARK: - Memory Token Store