front_end_builds icon indicating copy to clipboard operation
front_end_builds copied to clipboard

allow containing application to add `before_action` to front ends

Open alexdean opened this issue 8 years ago • 4 comments

problem

  1. my front-end application requires authentication/authorization (auth/authz) in order to do anything useful.
  2. for users who need auth/authz, i want to redirect them in rails, so as not to force them to load all of ember just to see a 'you are not authorized' message. i want all auth/authz logic & flows to be entirely in rails, and not require coordination in the ember code.
  3. currently the only way i can see to add a before_action to a front end build is via a monkey patch. this is brittle & a likely source for unexpected behavior

for example:

# config/initializers/front_end_builds.rb
module FrontEndBuilds
  class ApplicationController < ActionController::Base
    before_action :do_authentication_things
  end
end

possible solutions

i'm not stuck on either of these. just trying to brainstorm some options.

inherit from ::ApplicationController

change FrontEndBuilds::ApplicationController to inherit from ::ApplicationController. This gives the containing application a way to add before_action & other hooks without monkey patching

support a per-frontend before_action explicitly

# config/routes.rb
front_end 'something', '/', before_action: :do_authentication_things

this might be even nicer than the ::ApplicationController change, but i'm not sure how this would work exactly. (where/how would my :do_authentication_things method be defined?)

cc @samselikoff

alexdean avatar Apr 28 '16 15:04 alexdean