Skip to content

Commit 311c7f2

Browse files
committed
refactor: remove Pusher auth endpoint and update client configuration
- Deleted the Pusher private-channel auth endpoint to streamline the codebase. - Updated the Pusher client configuration to use a new auth endpoint and simplified the initialization process, enhancing clarity and maintainability.
1 parent 603fa3c commit 311c7f2

3 files changed

Lines changed: 9 additions & 19 deletions

File tree

src/components/providers/RealtimeProvider.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,17 @@ export function RealtimeProvider({ children }: PropsWithChildren) {
2828
if (!userId) return;
2929

3030
const pusher = getPusherClient();
31+
console.log("pusher", pusher);
3132
if (!pusher) return;
3233

3334
const channelName = `private-user.${userId}`;
3435
const channel = pusher.subscribe(channelName);
3536

3637
channel.bind("notification.new", () => {
3738
queryClient.invalidateQueries({ queryKey: ["my-notifications"] });
38-
queryClient.invalidateQueries({ queryKey: ["unread-notification-count"] });
39+
queryClient.invalidateQueries({
40+
queryKey: ["unread-notification-count"],
41+
});
3942
});
4043

4144
return () => {

src/lib/pusher.client.ts

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,28 +10,15 @@ let _pusherClient: Pusher | null = null;
1010
export function getPusherClient(): Pusher | null {
1111
if (typeof window === "undefined") return null;
1212

13-
const key = env.NEXT_PUBLIC_PUSHER_APP_KEY;
14-
if (!key) return null;
15-
1613
if (_pusherClient) return _pusherClient;
1714

18-
const forceTLS = env.NEXT_PUBLIC_PUSHER_FORCE_TLS !== "false";
19-
const port = env.NEXT_PUBLIC_PUSHER_PORT
20-
? Number(env.NEXT_PUBLIC_PUSHER_PORT)
21-
: undefined;
22-
2315
// pusher-js always requires cluster; use empty string as placeholder when
2416
// connecting to a self-hosted Soketi/compatible broker via wsHost.
25-
_pusherClient = new Pusher(key, {
26-
cluster: env.NEXT_PUBLIC_PUSHER_CLUSTER ?? "mt1",
27-
authEndpoint: "/api/pusher/auth",
28-
...(env.NEXT_PUBLIC_PUSHER_HOST && {
29-
wsHost: env.NEXT_PUBLIC_PUSHER_HOST,
30-
wsPort: port,
31-
wssPort: port,
32-
enabledTransports: ["ws", "wss"],
33-
}),
34-
forceTLS,
17+
_pusherClient = new Pusher(env.NEXT_PUBLIC_PUSHER_APP_KEY ?? "", {
18+
cluster: "mt1",
19+
authEndpoint: "/api/socket/auth",
20+
wsHost: env.NEXT_PUBLIC_PUSHER_HOST,
21+
enabledTransports: ["ws", "wss"],
3522
});
3623

3724
return _pusherClient;

0 commit comments

Comments
 (0)