From 22d82e966b6abac57ecc308051656f7c9ea68bfd Mon Sep 17 00:00:00 2001 From: Guilherme Souza Date: Tue, 3 Dec 2024 14:00:16 -0300 Subject: [PATCH] add docs --- Sources/Realtime/V2/RealtimeClientV2.swift | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/Sources/Realtime/V2/RealtimeClientV2.swift b/Sources/Realtime/V2/RealtimeClientV2.swift index 139e1247..6d2a461d 100644 --- a/Sources/Realtime/V2/RealtimeClientV2.swift +++ b/Sources/Realtime/V2/RealtimeClientV2.swift @@ -365,9 +365,23 @@ public final class RealtimeClientV2: Sendable { } /// Sets the JWT access token used for channel subscription authorization and Realtime RLS. - /// - Parameter token: A JWT string. - public func setAuth(_ token: String?) async { - mutableState.withValue { + /// + /// If `token` is nil it will use the ``RealtimeClientOptions/accessToken`` callback function or the token set on the client. + /// + /// On callback used, it will set the value of the token internal to the client. + /// - Parameter token: A JWT string to override the token set on the client. + public func setAuth(_ token: String? = nil) async { + var token = token + + if token == nil { + token = try? await options.accessToken?() + } + + if token == nil { + token = mutableState.accessToken + } + + mutableState.withValue { [token] in $0.accessToken = token }