Skip to content

Commit b9859a4

Browse files
authored
Merge pull request #270 from supabase/project-walrus
feat: add user_token when creating realtime channel subscription
2 parents d759e8d + 52d417c commit b9859a4

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

src/lib/SupabaseQueryBuilder.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export class SupabaseQueryBuilder<T> extends PostgrestQueryBuilder<T> {
2323
) {
2424
super(url, { headers, schema })
2525

26-
this._subscription = new SupabaseRealtimeClient(realtime, schema, table)
26+
this._subscription = new SupabaseRealtimeClient(realtime, headers, schema, table)
2727
this._realtime = realtime
2828
}
2929

src/lib/SupabaseRealtimeClient.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,21 @@ import { SupabaseEventTypes, SupabaseRealtimePayload } from './types'
44
export class SupabaseRealtimeClient {
55
subscription: RealtimeSubscription
66

7-
constructor(socket: RealtimeClient, schema: string, tableName: string) {
7+
constructor(
8+
socket: RealtimeClient,
9+
headers: { [key: string]: string },
10+
schema: string,
11+
tableName: string
12+
) {
13+
const chanParams: { [key: string]: string } = {}
814
const topic = tableName === '*' ? `realtime:${schema}` : `realtime:${schema}:${tableName}`
9-
this.subscription = socket.channel(topic)
15+
const userToken = headers['Authorization'].split(' ')[1]
16+
17+
if (userToken) {
18+
chanParams['user_token'] = userToken
19+
}
20+
21+
this.subscription = socket.channel(topic, chanParams)
1022
}
1123

1224
private getPayloadRecords(payload: any) {

0 commit comments

Comments
 (0)