Ruby Devise Admin model going 401 loop

Viewed 17

Rails 7, Devise 4.8

I had a basic Devise working fine with just a User Model. I needed a Dashboard protected from Users, so I added an Admin model for devise. I then created the devise admin routes and views as per the User pattern. I created a dashboard controller and protect it with the

before_action :authenticate_admin!

OK. So now I have problems. First off, when experimenting, I allowed a sign-up to the Admin, and what I provided is now considered an Admin. OK. So I have current_admin true.

But when I navigate to /dashboard to see that controller, it throws a 401 and redirects to /users/sign_in. Which in turn triggers the check via a concern for Admin or User, and since I am Admin, back to the dashboard... etc. etc.

So, if current_admin says I am good, why is the before action taking me to /users/sign_in and not just rendering my dashboard?

I tried everything but this 2 model approach seems busted without me doing something about that Accessible concern they recommend.

1 Answers

So this was due to naive use of Rails. Turns out my Application Controller of which all controllers usually inherit, has a before action assigned to asking for at least a User. Once I turned that off, the loop was cut.

Related