mirror of
https://github.com/stack-auth/stack.git
synced 2026-06-13 21:01:21 +08:00
Fix build
This commit is contained in:
parent
a91e6520c3
commit
7a2a324b23
@ -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
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user