Skip to content

Handle unauthorized #17

@sprite2005

Description

@sprite2005

I only allow authorized users to connect ActionCable, if the user is unauthorized I call reject_unauthorized_connection from Rails.

This sends a response

{
"type": "disconnect",
"reason": "unauthorized",
"reconnect": false
}

This package will crash on line 127 in action_cable.dart:

final channelId = parseChannelId(payload['identifier']);

Because there is no identifier as we are not yet connected to a channel and a channel disconnect callback wouldn't be appropriate anyways since it's disconnecting the client.

We need to check if reason is 'unauthorized' and then call either onConnectionLost or onCannotConnect. I think onCannotConnect would be most appropriate, perhaps even passing the reconnect: false so we know not to retry the connection.

Let me know if you want to make this change or if I should just fork.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions