我正在使用的设计令牌与反应前端,现在我是让用户确认通过电子邮件。电子邮件正在发送,但不知何故它生成了一个错误的URL。
生成的URL是。
http://localhost:3001/auth/confirmation.4?confirmation_token=AoWH2yYxuHHnBzJRF746
我的路线。
new_user_confirmation GET /auth/confirmation/new(.:format) users/confirmations#new
user_confirmation GET /auth/confirmation(.:format) users/confirmations#show
POST /auth/confirmation(.:format) users/confirmations#create我的app/views/devise/mailer/confirmation_instructions.html.erb
<p>Welcome <%= @email %>!</p>
<p>You can confirm your account email through the link below:</p>
<p><%= link_to 'Confirm my account', user_confirmation_url(confirmation_token: @token) %></p>单击“确认我的帐户”后,它会成功地将我带到我的应用程序,但使用错误的URL。如果我能做到以下其中之一,我会很高兴的。
。
对于1,我重写了类似的confirmations_controller.rb。
# frozen_string_literal: true
class Users::ConfirmationsController < Devise::ConfirmationsController
# The path used after confirmation.
def after_confirmation_path_for(resource_name, resource)
sign_in(resource) # In case you want to sign in the user
root_path
end
end在routes.rb中
mount_devise_token_auth_for 'User', at: 'auth', controllers: { confirmations: 'users/confirmations' }发布于 2020-04-10 16:15:56
首先,您在电子邮件中使用的url助手不需要接收@resource --这就是它使用.4生成url的原因。应该是
<p><%= link_to 'Confirm my account', user_confirmation_url(confirmation_token: @token) %></p第二,根据本教程,您可以在确认后重定向用户,就像您已经尝试过的一样。https://github.com/heartcombo/devise/wiki/How-To:-Add-:confirmable-to-Users#redirecting-user
在用户登录后,只需在应用程序中给出一个路径即可。
def after_confirmation_path_for(resource_name, resource)
sign_in(resource) # In case you want to sign in the user
your_new_after_confirmation_path
end因此,在登录后不需要再去session_new。
https://stackoverflow.com/questions/61139880
复制相似问题