将设计重定向到成功登录后似乎在第一次登录尝试时卡住了 [英] Devise redirect to on successful login seems to get stuck on first login attempt
问题描述
我正在使用Ruby on Rails并使用Devise进行身份验证来开发一个小型应用程序。我有两个登录系统设置,一个是 user
,另一个是 employee
I'm developing a small application using Ruby on Rails and using Devise for authentication. I've two login systems setup and one is user
and the other one is employee
使用正确的电子邮件和密码登录时,devise将正确的重定向发送回路径,但路径卡在那里。除非刷新页面,否则什么都不会继续。但是,一旦刷新它,它就会很高兴地转到重定向路径,即使在相同的浏览器选项卡中注销然后重新登录后也可以正常工作。但是,如果我关闭选项卡,然后将应用程序加载到新选项卡中,它将无法正常工作。
When logging in using correct email and password, devise sends the correct redirect to path back but it gets stuck there. Nothing continues unless I refresh the page. But once I refresh it, it will happily go to the redirect path and even if after logging out in the same browser tab and then logging back in works. But if I close the tab and then load the application in a new tab, it doesn't work.
以下是登录时的Rails服务器输出,
Following is the rails server output when logging in,
Started POST "/employees/sign_in" for ::1 at 2020-06-21 18:21:50 +0530
Processing by Devise::SessionsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"Pr0k+3+FfU72BcwTVRhWxQYBTD/zcv5+QBdWuovDRd4+yGxC1OBWmvAscWJbnog2vVTLpbPM2xOwVxGC3UsLRg==", "employee"=>{"email"=>"employee@example.com", "password"=>"[FILTERED]", "remember_me"=>"0"}, "commit"=>"Log in"}
Employee Load (0.4ms) SELECT "employees".* FROM "employees" WHERE "employees"."email" = $1 ORDER BY "employees"."id" ASC LIMIT $2 [["email", "employee@example.com"], ["LIMIT", 1]]
↳ app/controllers/application_controller.rb:23
CACHE Employee Load (0.0ms) SELECT "employees".* FROM "employees" WHERE "employees"."email" = $1 ORDER BY "employees"."id" ASC LIMIT $2 [["email", "employee@example.com"], ["LIMIT", 1]]
↳ app/controllers/application_controller.rb:23
Redirected to http://localhost:3000/employee/dashboard
Completed 302 Found in 818ms (ActiveRecord: 0.4ms)
我不确定为什么会发生这种情况,并且在尝试查找与此错误相关的内容时陷入僵局。
I'm not sure why this happens and hitting a dead end when trying to find anything related to this error.
以下是我的after_sign_in_path函数的代码
Following is the code for my after_sign_in_path function
def after_sign_in_path_for(resource)
set_flash_message! :alert, :warn_pwned if resource.respond_to?(:pwned?) && resource.pwned?
set_root
# super
end
此处 set_root
函数返回带有重定向路径的字符串。
Here set_root
function returns a String with the path for the redirect.
版本信息
Ruby version - ruby 2.6.0p0 (2018-12-25 revision 66547) [x86_64-darwin19]
Rails version - Rails 5.2.4.2
Devise version - 4.7.1
Turbolinks - Yes
推荐答案
尝试替换您的 form_for
在 sessions / new.html.erb
中带有 form_with
。我有一个类似的问题(Rails 6),现在看来还可以。
Try replacing your form_for
with form_with
in your sessions/new.html.erb
. I have a similar problem (Rails 6) and it seems to be ok now.
<%= form_with(model: resource, scope: resource_name, url: session_path(resource_name)) do |f| %>
此外,我没有评论<$ c $中的 Turbolinks
部分c> config / initializers / devise.rb :
Additionally, I uncommented the Turbolinks
section in config/initializers/devise.rb
:
ActiveSupport.on_load(:devise_failure_app) do
include Turbolinks::Controller
end
这篇关于将设计重定向到成功登录后似乎在第一次登录尝试时卡住了的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!