Rails before_action :authenticate_user! not redirecting -


context:

i'm using devise authentication. trying test behavior user has multiple windows open after sign in, log out of 1 window try make change on requires authentication. when submit form, should not post/ put/ delete whatever, , should instead redirect sign in page message need signed in. per other question posted: catch 401 error in rails devise when user has multiple windows open, i've learned devise's helper method: before_action :authenticate_user! handle redirect on behalf. great!

so have following controllers:

class staticpagescontroller < applicationcontroller   prepend_before_action :authenticate_user!, only: [:dashboard]    def dashboard end  class planscontroller < applicationcontroller   prepend_before_action :authenticate_user!    def create   def update   def destroy   ... end 

i can confirm using in console , local server authenticate_user! in fact first filter in both controllers

puts self._process_action_callbacks.select { |c| c.kind == :before }.map(&:filter) 

problem

the problem appears working in staticpagescontroller dashboard action. might because in /dashboard test can page refresh, not take actions (since form actions go planscontroller), here's behavior now:

  • if have 2 /dashboard pages open, sign out on 1 , refresh other, on latter redirected sign in page notice sign in
  • if have 2 /dashboard pages open, sign out on one, , attempt submit form on other (dashboard designed single page app, form present on load), rather redirected, instead plain text error i'm not logged in (and 401 response)

given this, suspect that:

  • either authenticate_user! not responsible redirect, , else (in case tell me what!)
  • or authenticate_user! working in 1 controller

help please! ensure user redirected...

now, way, tried fiddle myself, catch 401 , redirect, got stuck (that original question linked above, , commented shouldn't have because devise me... i'm @ now).


Comments

Popular posts from this blog

c# - Better 64-bit byte array hash -

webrtc - Which ICE candidate am I using and why? -

php - Zend Framework / Skeleton-Application / Composer install issue -