Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add user_token when creating realtime channel subscription #270

Merged
merged 1 commit into from Sep 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/lib/SupabaseQueryBuilder.ts
Expand Up @@ -23,7 +23,7 @@ export class SupabaseQueryBuilder<T> extends PostgrestQueryBuilder<T> {
) {
super(url, { headers, schema })

this._subscription = new SupabaseRealtimeClient(realtime, schema, table)
this._subscription = new SupabaseRealtimeClient(realtime, headers, schema, table)
this._realtime = realtime
}

Expand Down
16 changes: 14 additions & 2 deletions src/lib/SupabaseRealtimeClient.ts
Expand Up @@ -4,9 +4,21 @@ import { SupabaseEventTypes, SupabaseRealtimePayload } from './types'
export class SupabaseRealtimeClient {
subscription: RealtimeSubscription

constructor(socket: RealtimeClient, schema: string, tableName: string) {
constructor(
socket: RealtimeClient,
headers: { [key: string]: string },
schema: string,
tableName: string
) {
const chanParams: { [key: string]: string } = {}
const topic = tableName === '*' ? `realtime:${schema}` : `realtime:${schema}:${tableName}`
this.subscription = socket.channel(topic)
const userToken = headers['Authorization'].split(' ')[1]

if (userToken) {
chanParams['user_token'] = userToken
}

this.subscription = socket.channel(topic, chanParams)
}

private getPayloadRecords(payload: any) {
Expand Down