cancel actioncable connection for unauthorized users?
Followed the series on action cable notifications and setup the meta tag so that action would not try to connect if the meta tag was present. Here is my code.
$(document).on("turbolinks:load", function () {
if ($("meta[name='current_user']").length > 0) {
App.activity_feed = App.cable.subscriptions.create("ActivityFeedChannel", {
connected: function() {console.log("I connected")},
disconnected: function() {console.log("I disconnected")},
received: function(data) {
$("#completed-timeline-ul").prepend(data.html);
}
});
};
});
I tried it with and without the turbolinks code as well.. no dice.
I look in the dev tools and see that the meta tag is present and when I run $("meta[name='current_user']").length > 0
in the console it comes back as true.
Not sure what i'm missing. If i get rid of the if statment actioncable connects successfully.
Thanks for the help.