11import type { PusherTransportConfig , RealtimeNotificationPayload } from '../../types'
2+ import { RequestException , env } from '@arkstack/common'
23
34import type { RealtimeDriver } from '../../Contracts/RealtimeDriver'
4- import { env } from '@arkstack/common'
55
66/** The slice of the `pusher` server SDK this driver uses. */
77interface PusherClient {
@@ -112,6 +112,7 @@ export class PusherRealtimeDriver implements RealtimeDriver {
112112 async registerAuthRoute (
113113 authEndpoint : string = '/realtime/auth' ,
114114 middleware ?: unknown | unknown [ ] ,
115+ channelPrefix ?: string
115116 ) : Promise < void > {
116117 const client = await this . client ( )
117118 const drivers = {
@@ -130,10 +131,15 @@ export class PusherRealtimeDriver implements RealtimeDriver {
130131 : [ middleware , auth ]
131132 )
132133
133- Router . post ( authEndpoint , ( { clearRequest } : any ) => {
134+ Router . post ( authEndpoint , ( { clearRequest, req } : any ) => {
134135 const channel = clearRequest . input ( 'channel_name' )
135136 const socketId = clearRequest . input ( 'socket_id' )
136137
138+ const expected = channelPrefix ??
139+ `${ config ( 'notifications.drivers.realtime.channel_prefix' , 'user.' ) } ${ req . user ?. id ?? clearRequest . user ?. id } `
140+
141+ RequestException . abortIf ( channel !== expected , 'Channel access denied' , 403 )
142+
137143 return client . authorizeChannel ( socketId , channel )
138144 } ) . middleware ( Array . from ( middlewares ) )
139145
0 commit comments