-
-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: push access token to every channel during heartbeat
- Loading branch information
Showing
2 changed files
with
16 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,6 +34,7 @@ type Message = { | |
const noop = () => {} | ||
|
||
export default class RealtimeClient { | ||
accessToken: string | null = null | ||
channels: RealtimeSubscription[] = [] | ||
endPoint: string = '' | ||
headers?: { [key: string]: string } = DEFAULT_HEADERS | ||
|
@@ -317,6 +318,15 @@ export default class RealtimeClient { | |
return this.ref.toString() | ||
} | ||
|
||
/** | ||
* Sets the JWT access token used for channel subscription authorization and Realtime RLS. | ||
* | ||
* @param token A JWT string. | ||
*/ | ||
setAccessToken(token: string) { | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong. |
||
this.accessToken = token | ||
} | ||
|
||
private _onConnOpen() { | ||
this.log('transport', `connected to ${this.endPointURL()}`) | ||
this._flushSendBuffer() | ||
|
@@ -391,5 +401,10 @@ export default class RealtimeClient { | |
payload: {}, | ||
ref: this.pendingHeartbeatRef, | ||
}) | ||
this.channels.forEach((channel) => | ||
channel.push(CHANNEL_EVENTS.access_token, { | ||
access_token: this.accessToken, | ||
}) | ||
) | ||
This comment has been minimized.
Sorry, something went wrong.
kiwicopple
Member
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
in GoTrue this one is called
setAuth()
:https://github.com/supabase/gotrue-js/blob/ec799e5dc5565ecdb905148b5b0b12a497657bda/src/GoTrueClient.ts#L382
Should we make the naming convention the same?