Skip to content

Commit 22d82e9

Browse files
committed
add docs
1 parent f637fb4 commit 22d82e9

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

Sources/Realtime/V2/RealtimeClientV2.swift

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -365,9 +365,23 @@ public final class RealtimeClientV2: Sendable {
365365
}
366366

367367
/// Sets the JWT access token used for channel subscription authorization and Realtime RLS.
368-
/// - Parameter token: A JWT string.
369-
public func setAuth(_ token: String?) async {
370-
mutableState.withValue {
368+
///
369+
/// If `token` is nil it will use the ``RealtimeClientOptions/accessToken`` callback function or the token set on the client.
370+
///
371+
/// On callback used, it will set the value of the token internal to the client.
372+
/// - Parameter token: A JWT string to override the token set on the client.
373+
public func setAuth(_ token: String? = nil) async {
374+
var token = token
375+
376+
if token == nil {
377+
token = try? await options.accessToken?()
378+
}
379+
380+
if token == nil {
381+
token = mutableState.accessToken
382+
}
383+
384+
mutableState.withValue { [token] in
371385
$0.accessToken = token
372386
}
373387

0 commit comments

Comments
 (0)