我正在使用带有 React 前端的设计令牌身份验证,现在我正在通过电子邮件确认用户。正在发送电子邮件,但不知何故它生成了错误的 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
我的应用程序/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,我已经覆盖了 confirms_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
在路线.rb
mount_devise_token_auth_for 'User', at: 'auth', controllers: { confirmations: 'users/confirmations' }