Skip to content

Commit 6264e7e

Browse files
committed
pull token from third party or fallback to auth
1 parent 22d82e9 commit 6264e7e

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

Sources/Supabase/SupabaseClient.swift

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -348,12 +348,7 @@ public final class SupabaseClient: Sendable {
348348
}
349349

350350
private func adapt(request: URLRequest) async -> URLRequest {
351-
let token: String? =
352-
if let accessToken = options.auth.accessToken {
353-
try? await accessToken()
354-
} else {
355-
try? await auth.session.accessToken
356-
}
351+
let token = try? await _getAccessToken()
357352

358353
var request = request
359354
if let token {
@@ -362,6 +357,14 @@ public final class SupabaseClient: Sendable {
362357
return request
363358
}
364359

360+
private func _getAccessToken() async throws -> String {
361+
if let accessToken = options.auth.accessToken {
362+
try await accessToken()
363+
} else {
364+
try await auth.session.accessToken
365+
}
366+
}
367+
365368
private func listenForAuthEvents() {
366369
let task = Task {
367370
for await (event, session) in auth.authStateChanges {
@@ -404,8 +407,7 @@ public final class SupabaseClient: Sendable {
404407

405408
if realtimeOptions.accessToken == nil {
406409
realtimeOptions.accessToken = { [weak self] in
407-
guard let self else { return "" }
408-
return try await self.auth.session.accessToken
410+
try await self?._getAccessToken() ?? ""
409411
}
410412
} else {
411413
reportIssue(

0 commit comments

Comments
 (0)