Skip to content

Commit af9b774

Browse files
authored
fix: Make the return value of accessToken nullable (#641)
1 parent 6b0a0ea commit af9b774

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

Sources/Realtime/V2/Types.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public struct RealtimeClientOptions: Sendable {
2222
var disconnectOnSessionLoss: Bool
2323
var connectOnSubscribe: Bool
2424
var fetch: (@Sendable (_ request: URLRequest) async throws -> (Data, URLResponse))?
25-
package var accessToken: (@Sendable () async throws -> String)?
25+
package var accessToken: (@Sendable () async throws -> String?)?
2626
package var logger: (any SupabaseLogger)?
2727

2828
public static let defaultHeartbeatInterval: TimeInterval = 15
@@ -39,7 +39,7 @@ public struct RealtimeClientOptions: Sendable {
3939
disconnectOnSessionLoss: Bool = Self.defaultDisconnectOnSessionLoss,
4040
connectOnSubscribe: Bool = Self.defaultConnectOnSubscribe,
4141
fetch: (@Sendable (_ request: URLRequest) async throws -> (Data, URLResponse))? = nil,
42-
accessToken: (@Sendable () async throws -> String)? = nil,
42+
accessToken: (@Sendable () async throws -> String?)? = nil,
4343
logger: (any SupabaseLogger)? = nil
4444
) {
4545
self.headers = HTTPFields(headers)

Sources/Supabase/SupabaseClient.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ public final class SupabaseClient: Sendable {
357357
return request
358358
}
359359

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

408408
if realtimeOptions.accessToken == nil {
409409
realtimeOptions.accessToken = { [weak self] in
410-
try await self?._getAccessToken() ?? ""
410+
try await self?._getAccessToken()
411411
}
412412
} else {
413413
reportIssue(

Sources/Supabase/Types.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public struct SupabaseClientOptions: Sendable {
6464
/// 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.
6565
/// When set, the `auth` namespace of the Supabase client cannot be used.
6666
/// Create another client if you wish to use Supabase Auth and third-party authentications concurrently in the same application.
67-
public let accessToken: (@Sendable () async throws -> String)?
67+
public let accessToken: (@Sendable () async throws -> String?)?
6868

6969
public init(
7070
storage: any AuthLocalStorage,
@@ -74,7 +74,7 @@ public struct SupabaseClientOptions: Sendable {
7474
encoder: JSONEncoder = AuthClient.Configuration.jsonEncoder,
7575
decoder: JSONDecoder = AuthClient.Configuration.jsonDecoder,
7676
autoRefreshToken: Bool = AuthClient.Configuration.defaultAutoRefreshToken,
77-
accessToken: (@Sendable () async throws -> String)? = nil
77+
accessToken: (@Sendable () async throws -> String?)? = nil
7878
) {
7979
self.storage = storage
8080
self.redirectToURL = redirectToURL
@@ -163,7 +163,7 @@ extension SupabaseClientOptions.AuthOptions {
163163
encoder: JSONEncoder = AuthClient.Configuration.jsonEncoder,
164164
decoder: JSONDecoder = AuthClient.Configuration.jsonDecoder,
165165
autoRefreshToken: Bool = AuthClient.Configuration.defaultAutoRefreshToken,
166-
accessToken: (@Sendable () async throws -> String)? = nil
166+
accessToken: (@Sendable () async throws -> String?)? = nil
167167
) {
168168
self.init(
169169
storage: AuthClient.Configuration.defaultLocalStorage,

0 commit comments

Comments
 (0)