Pusher only for logged in users
Well, i rlly don't know what to do
- Edited
Tried to find something on pusher documentation but all that got is about autenthication, not blocking if user is a "guest" from database, thinks about blocking websocket connection on that case but don't know how to do that.
It would probably be enough to load Pusher conditionally based on whether the user is logged in or not.
https://github.com/flarum/pusher/blob/v0.1.0-beta.9/js/src/forum/index.js
Not sure what happens when the user logs in though, I don't remember if the page gets refreshed.
matteocontrini thank u for reply.
Is possible make that on the extend.php file or is necessary "mess" the pusher files?
Oh man! I think i'm getting what u meam now, instead of blocking a working script from a conditional u mean don't activate extension but run the file from a conditional?
I mean changing the content of that file so that Pusher is loaded only when you want it to load on the client side (browser).
You would need to fork the extension though, then change something in that file, build the JavaScript frontend and replace the extension with the forked one.
matteocontrini i will try on localhost, if for some miracle i take it (hahaha) i publish here to help all guys that uses free version of pusher and cry about the 100 connections limit.
Thank u so much! @matteocontrini
matteocontrini Not sure what happens when the user logs in though, I don't remember if the page gets refreshed
Yes currently the page is fully reloaded each time a user logs in or out, so it should be possible for a backend extension to conditionally remove any Pusher initializer from the front-end.
clarkwinkelmann I think it can be done directly on the client side, something like:
if (!app.data.session.userId) return;
to exclude all the frontend Pusher initialization code.
- Edited
Has anyone managed to make Pusher work only for logged in users? I have 4 online users and already received Pusher warning that the max number of connections is reached (100). I don’t need all those non-registered users to use Pusher and exhaust it for the logged in users.
@matteocontrini , how can your code be integrated easily?
P.S. Looking at the Pusher stats it seems a single spike around a very stable and flat low usage. To me this is either a single faulty web client that somehow spawns many connections (Flarum/Pusher extension bug?) or a malicious thing but I really doubt that someone would target Pusher rather than the forum itself. I don’t see any CloudFlare spikes, so it’s not correlated to increased number of users.