You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have been following the tutorial for Subscribing to Database Changes with the Swift client. The Swift client does not receive the database messages when triggered (like a record is updated), however, the JS client does receive the database messages.
I believe it's because supabase.realtimeV2.setAuth() does not send JWT credentials to channels because of this guard statement:
The problem seems to be that since await realtimeV2.setAuth(accessToken) is called in the initializing of SupabaseClient, it's triggered before we can subscribe to any channels. So if we have code like this:
The setAuth() call does not send JWT auth to the channels, because the guard gets kicked in since the accessToken hasn't changed from initializing SupabaseClient:
publicfunc setAuth(_ token:String?=nil)async{vartokenToSend= token
if tokenToSend ==nil{
tokenToSend =try?await options.accessToken?()}
// 👇 guard kicks in, so the for channel in channels loop never get fired
guard tokenToSend != mutableState.accessToken else{return}
mutableState.withValue{[token]in
$0.accessToken = token
}forchannelin channels.values {if channel.status ==.subscribed {
options.logger?.debug("Updating auth token for channel \(channel.topic)")await channel.push(ChannelEvent.accessToken,
payload:["access_token": token.map{.string($0)}??.null])}}}
Now it's very possible I'm just doing something wrong or completely missed a piece, but it seems like it's impossible to push accessTokens to channels since SupabaseClient sets the accessToken at initialization. Please let me know if I'm off base though and there's another reason!
The text was updated successfully, but these errors were encountered:
Thanks for the quick response @grdsdev. That makes sense that it sends the accessToken on subscribe. So the for channel in channels loop in setAuth is just for when the user gets a new accessToken. Got it.
Yes, please let me know if you're successful with the Swift client and the tutorial!
I'm updating our SlackClone example to use broadcast changes. You can follow along in this still-draft PR: #723
Also, from what I'm seeing in your code sample, you're missing setting the channel to private. Broadcast changes only work for private channels. This is how you do it:
I have been following the tutorial for Subscribing to Database Changes with the Swift client. The Swift client does not receive the database messages when triggered (like a record is updated), however, the JS client does receive the database messages.
I believe it's because supabase.realtimeV2.setAuth() does not send JWT credentials to channels because of this guard statement:
Spelunking session
let supabase = SupabaseClient(...)
)listenForAuthEvents()
listenForAuthEvents()
callshandleTokenChanged(...)
handleTokenChanges()
callsawait realtimeV2.setAuth(accessToken)
The problem seems to be that since
await realtimeV2.setAuth(accessToken)
is called in the initializing of SupabaseClient, it's triggered before we can subscribe to any channels. So if we have code like this:The
setAuth()
call does not send JWT auth to the channels, because the guard gets kicked in since the accessToken hasn't changed from initializing SupabaseClient:realtimeV2.setAuth():
Now it's very possible I'm just doing something wrong or completely missed a piece, but it seems like it's impossible to push accessTokens to channels since SupabaseClient sets the accessToken at initialization. Please let me know if I'm off base though and there's another reason!
The text was updated successfully, but these errors were encountered: