Skip to content

Commit

Permalink
Merge pull request #270 from supabase/project-walrus
Browse files Browse the repository at this point in the history
feat: add user_token when creating realtime channel subscription
  • Loading branch information
w3b6x9 committed Sep 22, 2021
2 parents d759e8d + 52d417c commit b9859a4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
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

0 comments on commit b9859a4

Please sign in to comment.