We use Guardian to generate tokens, which we then use for authentication when connecting to Phoenix Channels' socket.
Recently we found that some users never leave certain pages, and after a month or so, the token becomes invalid, which invalidates the Phoenix Channels connection attempt.
How do you handle such cases on the client-side? Is there a particular error that can be returned from Phoenix to let the front-end know what is the reason? Our connect
function in user_socket.ex
looks like so:
def connect(%{"guardian_token" => token}, socket) do
case Guardian.Phoenix.Socket.authenticate(socket, MyApp.Guardian, token) do
{:ok, authed_socket} ->
{:ok, authed_socket}
{:error, _} ->
:error
end
end
Is there a way to capture this error using the Phoenix JS library for Phoenix Channels? Our goal is to 1) stop it from retrying if the token is expired, 2) potentially log out the user or show a message that the user is offline. We checked the Phoenix JS' documentation but couldn't find anything suitable.