Use case
When building a native app with log-in screen we may create the cable connection early, e.g. as part of GraphQL subscription initialization. This connection may then either fail to load as it will be unable to generate JWT or it may log-in as not logged in user depending on the server configuration.
The problem is when we then log-in as the user. There's no easy way to reset or recreate the Cable instance resulting in a subtle bug where the first login to the app does not work as expected. Similar problem happens when logging out and logging back in again as the connection has already been closed by the user.
The way we tried to work around this was by triggering cable.cable.connect() when user signs in but it comes with another subtle issue - the initial flag is no longer true so this code snippet from README no longer works as expected:
transportConfigurator: async (transport, { initial }) => {
// The initial flag indicates whether this is the first connetion attempt or a reconnection
if (!initial) return;
transport.setURL('ws://example.com/cable')
let response = await fetch('/token.json')
let data = await response.json()
transport.setToken(data['token'], 'token')
}
This can be worked around by manually checking that jid is missing or set to null in the transport.url but it would be great to have some built-in option that doesn't rely on this type of heuristic.
Use case
When building a native app with log-in screen we may create the cable connection early, e.g. as part of GraphQL subscription initialization. This connection may then either fail to load as it will be unable to generate JWT or it may log-in as not logged in user depending on the server configuration.
The problem is when we then log-in as the user. There's no easy way to reset or recreate the Cable instance resulting in a subtle bug where the first login to the app does not work as expected. Similar problem happens when logging out and logging back in again as the connection has already been closed by the user.
The way we tried to work around this was by triggering
cable.cable.connect()when user signs in but it comes with another subtle issue - theinitialflag is no longertrueso this code snippet from README no longer works as expected:This can be worked around by manually checking that
jidis missing or set tonullin thetransport.urlbut it would be great to have some built-in option that doesn't rely on this type of heuristic.