Active Admin login for admin users redirects back to the login page with correct credentials only in Chrome on localhost

不问归期 提交于 2020-04-07 08:02:25

问题


I am only having this problem locally in Chrome, not in production. It is also not a problem in Safari or Firefox. I am not sure what caused the problem as my only recent change was adding Redis/Sidekiq for asynchronously handling jobs, which doesn't seem relevant.

I cleared my cookies in Chrome and it still did not help.

The problem started after I reset the local database and loaded in my seeds and example data. I used psql to look at the data in the database and can confirm that I have the correct users and admin users in place to be able to authenticate through the Active Admin sign in page.

When I use incorrect credentials I get the appropriate "Invalid Email or password." message in Active Admin, which is expected, and I see the expected output in terminal: "Completed 401 Unauthorized" etc.

When I use the correct credentials I have the problem. I get redirected back to the same page (it looks like the page just refreshes).

In the terminal I can see a 302 and a redirect to the admin page where I am not authenticated (don't know why), which is causing me to redirect back to the log in page.

Terminal output for failing login attempt in Chrome:

Incoming Headers:
  Origin: http://localhost:3000
  Path-Info: /admin/login
  Access-Control-Request-Method: 
  Access-Control-Request-Headers: 
Started POST "/admin/login" for ::1 at 2020-03-14 01:15:49 -0500
Processing by ActiveAdmin::Devise::SessionsController#create as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"Qirj5VE07/Xv2c3vrwNzmNH3pIfrd615p+OnaXV8cSWVeeIaEBIWRAK8tsquti5KgqmJv/sgmGD84VQCxkmKdg==", "admin_user"=>{"email"=>"mishaherscu@gmail.com", "password"=>"[FILTERED]", "remember_me"=>"0"}, "commit"=>"Login"}
  AdminUser Load (0.2ms)  SELECT "admin_users".* FROM "admin_users" WHERE "admin_users"."id" = $1 ORDER BY "admin_users"."id" ASC LIMIT $2  [["id", 1], ["LIMIT", 1]]
  AdminUser Load (0.3ms)  SELECT "admin_users".* FROM "admin_users" WHERE "admin_users"."email" = $1 ORDER BY "admin_users"."id" ASC LIMIT $2  [["email", "mishaherscu@gmail.com"], ["LIMIT", 1]]
Redirected to http://localhost:3000/admin
Completed 302 Found in 121ms (ActiveRecord: 0.5ms | Allocations: 3418)


::1 - - [14/Mar/2020:01:15:49 CDT] "POST /admin/login HTTP/1.1" 302 93
http://localhost:3000/admin/login -> /admin/login
Started GET "/admin" for ::1 at 2020-03-14 01:15:49 -0500
Processing by Admin::DashboardController#index as HTML
  AdminUser Load (0.2ms)  SELECT "admin_users".* FROM "admin_users" WHERE "admin_users"."id" = $1 ORDER BY "admin_users"."id" ASC LIMIT $2  [["id", 1], ["LIMIT", 1]]
Completed 401 Unauthorized in 2ms (ActiveRecord: 0.2ms | Allocations: 611)


::1 - - [14/Mar/2020:01:15:49 CDT] "GET /admin HTTP/1.1" 302 99
http://localhost:3000/admin/login -> /admin
Started GET "/admin/login" for ::1 at 2020-03-14 01:15:49 -0500
Processing by ActiveAdmin::Devise::SessionsController#new as HTML
  AdminUser Load (0.7ms)  SELECT "admin_users".* FROM "admin_users" WHERE "admin_users"."id" = $1 ORDER BY "admin_users"."id" ASC LIMIT $2  [["id", 1], ["LIMIT", 1]]
  Rendering /Users/mishaherscu/.rbenv/versions/2.6.1/lib/ruby/gems/2.6.0/gems/activeadmin-2.6.1/app/views/active_admin/devise/sessions/new.html.erb within layouts/active_admin_logged_out
  Rendered /Users/mishaherscu/.rbenv/versions/2.6.1/lib/ruby/gems/2.6.0/gems/activeadmin-2.6.1/app/views/active_admin/devise/shared/_links.erb (Duration: 0.2ms | Allocations: 93)
  Rendered /Users/mishaherscu/.rbenv/versions/2.6.1/lib/ruby/gems/2.6.0/gems/activeadmin-2.6.1/app/views/active_admin/devise/sessions/new.html.erb within layouts/active_admin_logged_out (Duration: 7.5ms | Allocations: 6691)
Completed 200 OK in 34ms (Views: 31.0ms | ActiveRecord: 0.7ms | Allocations: 30877)

Terminal output for successful login attempt in Safari:

Incoming Headers:
  Origin: http://localhost:3000
  Path-Info: /admin/login
  Access-Control-Request-Method: 
  Access-Control-Request-Headers: 
Started POST "/admin/login" for ::1 at 2020-03-14 14:05:32 -0500
Processing by ActiveAdmin::Devise::SessionsController#create as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"Zr9FK5J4+tc+/a/RY4ir84YWi/MkIfnTRzAj3sg5yrqb7o8yuIggXu+mT273TN1xzNCFH9EYP2DVYZMte2JUEw==", "admin_user"=>{"email"=>"mishaherscu@gmail.com", "password"=>"[FILTERED]", "remember_me"=>"1"}, "commit"=>"Login"}
  AdminUser Load (0.2ms)  SELECT "admin_users".* FROM "admin_users" WHERE "admin_users"."email" = $1 ORDER BY "admin_users"."id" ASC LIMIT $2  [["email", "mishaherscu@gmail.com"], ["LIMIT", 1]]
   (0.2ms)  BEGIN
  AdminUser Update (0.2ms)  UPDATE "admin_users" SET "remember_created_at" = $1, "updated_at" = $2 WHERE "admin_users"."id" = $3  [["remember_created_at", "2020-03-14 19:05:32.213581"], ["updated_at", "2020-03-14 19:05:32.213742"], ["id", 1]]
   (0.9ms)  COMMIT
Redirected to http://localhost:3000/admin
Completed 302 Found in 101ms (ActiveRecord: 1.4ms | Allocations: 1308)


::1 - - [14/Mar/2020:14:05:32 CDT] "POST /admin/login HTTP/1.1" 302 93
http://localhost:3000/admin/login -> /admin/login
Incoming Headers:
  Origin: http://localhost:3000
  Path-Info: /admin
  Access-Control-Request-Method: 
  Access-Control-Request-Headers: 
Started GET "/admin" for ::1 at 2020-03-14 14:05:32 -0500
Processing by Admin::DashboardController#index as HTML
  AdminUser Load (0.1ms)  SELECT "admin_users".* FROM "admin_users" WHERE "admin_users"."id" = $1 ORDER BY "admin_users"."id" ASC LIMIT $2  [["id", 1], ["LIMIT", 1]]
  Rendering /Users/mishaherscu/.rbenv/versions/2.6.1/lib/ruby/gems/2.6.0/gems/activeadmin-2.6.1/app/views/active_admin/page/index.html.arb
  Rendered /Users/mishaherscu/.rbenv/versions/2.6.1/lib/ruby/gems/2.6.0/gems/activeadmin-2.6.1/app/views/active_admin/page/index.html.arb (Duration: 25.0ms | Allocations: 32977)
Completed 200 OK in 26ms (Views: 25.4ms | ActiveRecord: 0.1ms | Allocations: 33501)


::1 - - [14/Mar/2020:14:05:32 CDT] "GET /admin HTTP/1.1" 200 5255
http://localhost:3000/admin/login -> /admin

From routes.rb:

devise_for :admin_users, ActiveAdmin::Devise.config
ActiveAdmin.routes(self)

Does anyone have any ideas about what is causing it and/or how it could be fixed? Also happy to provide additional information if anything is missing.


回答1:


This ended up working, with a bunch of finagling:

https://github.com/codica2/rails-puma-ssl

I am now using something like this to launch rails on localhost: rails s -b 'ssl://localhost:3000?key=server.key&cert=server.crt'

In /etc/hosts, I had to change 127.0.0.1 localhost to 127.0.0.1 localhost.ssl

To see localhost, I have to add the "s" so, for example, Active Admin is here: https://localhost:3000/admin



来源:https://stackoverflow.com/questions/60680271/active-admin-login-for-admin-users-redirects-back-to-the-login-page-with-correct

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!