Skip to content

ActionPolicy authorization during broadcast Turbo Streams using Devise #254

Answered by palkan
danielnc asked this question in Q&A
Discussion options

You must be logged in to vote

Hey!

How do I inject the current_user in the broadcast_append_later to be used by action policy? I have the current user in a thread-safe object(Current.user) but not sure how to broadcast rendering partials that depend on action policy specific authorization methods

It's almost impossible with Hotwire. The problem is that the Turbo Stream partial is rendered without any user context (it's rendered within a background job and once for all users). What you need is to render a partial per user.

There are several ways of dealing with this problem (I call it the personalization problem, see this talk):

  • Enhance UI on the client-side via Stimulus (or similar); render controls hidden by defa…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by danielnc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants