Skip to content

Commit

Permalink
fix(realtime): send access token to realtime on initial session (#439)
Browse files Browse the repository at this point in the history
  • Loading branch information
grdsdev authored Jul 2, 2024
1 parent 1bfabfa commit 048e81b
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions Sources/Supabase/SupabaseClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -353,16 +353,18 @@ public final class SupabaseClient: Sendable {
}

private func handleTokenChanged(event: AuthChangeEvent, session: Session?) async {
let accessToken = mutableState.withValue {
if event == .tokenRefreshed || event == .signedIn, $0.changedAccessToken != session?.accessToken {
let accessToken: String? = mutableState.withValue {
if [.initialSession, .signedIn, .tokenRefreshed].contains(event), $0.changedAccessToken != session?.accessToken {
$0.changedAccessToken = session?.accessToken
return session?.accessToken
} else if event == .signedOut {
return session?.accessToken ?? supabaseKey
}

if event == .signedOut {
$0.changedAccessToken = nil
return supabaseKey
} else {
return nil
}

return nil
}

realtime.setAuth(accessToken)
Expand Down

0 comments on commit 048e81b

Please # to comment.