Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: make the return value of accessToken nullable #641

Merged
merged 1 commit into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Sources/Realtime/V2/Types.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public struct RealtimeClientOptions: Sendable {
var disconnectOnSessionLoss: Bool
var connectOnSubscribe: Bool
var fetch: (@Sendable (_ request: URLRequest) async throws -> (Data, URLResponse))?
package var accessToken: (@Sendable () async throws -> String)?
package var accessToken: (@Sendable () async throws -> String?)?
package var logger: (any SupabaseLogger)?

public static let defaultHeartbeatInterval: TimeInterval = 15
Expand All @@ -39,7 +39,7 @@ public struct RealtimeClientOptions: Sendable {
disconnectOnSessionLoss: Bool = Self.defaultDisconnectOnSessionLoss,
connectOnSubscribe: Bool = Self.defaultConnectOnSubscribe,
fetch: (@Sendable (_ request: URLRequest) async throws -> (Data, URLResponse))? = nil,
accessToken: (@Sendable () async throws -> String)? = nil,
accessToken: (@Sendable () async throws -> String?)? = nil,
logger: (any SupabaseLogger)? = nil
) {
self.headers = HTTPFields(headers)
Expand Down
4 changes: 2 additions & 2 deletions Sources/Supabase/SupabaseClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ public final class SupabaseClient: Sendable {
return request
}

private func _getAccessToken() async throws -> String {
private func _getAccessToken() async throws -> String? {
if let accessToken = options.auth.accessToken {
try await accessToken()
} else {
Expand Down Expand Up @@ -407,7 +407,7 @@ public final class SupabaseClient: Sendable {

if realtimeOptions.accessToken == nil {
realtimeOptions.accessToken = { [weak self] in
try await self?._getAccessToken() ?? ""
try await self?._getAccessToken()
}
} else {
reportIssue(
Expand Down
6 changes: 3 additions & 3 deletions Sources/Supabase/Types.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public struct SupabaseClientOptions: Sendable {
/// Note that this function may be called concurrently and many times. Use memoization and locking techniques if this is not supported by the client libraries.
/// When set, the `auth` namespace of the Supabase client cannot be used.
/// Create another client if you wish to use Supabase Auth and third-party authentications concurrently in the same application.
public let accessToken: (@Sendable () async throws -> String)?
public let accessToken: (@Sendable () async throws -> String?)?

public init(
storage: any AuthLocalStorage,
Expand All @@ -74,7 +74,7 @@ public struct SupabaseClientOptions: Sendable {
encoder: JSONEncoder = AuthClient.Configuration.jsonEncoder,
decoder: JSONDecoder = AuthClient.Configuration.jsonDecoder,
autoRefreshToken: Bool = AuthClient.Configuration.defaultAutoRefreshToken,
accessToken: (@Sendable () async throws -> String)? = nil
accessToken: (@Sendable () async throws -> String?)? = nil
) {
self.storage = storage
self.redirectToURL = redirectToURL
Expand Down Expand Up @@ -163,7 +163,7 @@ extension SupabaseClientOptions.AuthOptions {
encoder: JSONEncoder = AuthClient.Configuration.jsonEncoder,
decoder: JSONDecoder = AuthClient.Configuration.jsonDecoder,
autoRefreshToken: Bool = AuthClient.Configuration.defaultAutoRefreshToken,
accessToken: (@Sendable () async throws -> String)? = nil
accessToken: (@Sendable () async throws -> String?)? = nil
) {
self.init(
storage: AuthClient.Configuration.defaultLocalStorage,
Expand Down
Loading