我包括devise_token_auth
从其他地方托管的网络应用程序登录。但我也希望能够直接登录到我的 rails 应用程序。
我的 routes.rb 看起来像这样:
#...
devise_for :users
namespace :api, defaults: {format: :json} do
mount_devise_token_auth_for 'User', at: 'auth'
#...
为了重置密码,webapp 发送一个POST
到/api/auth/password
. 使用上面的配置,电子邮件中重置密码的链接使用了错误的控制器(打开的那个users/password
)。redirect_url 没有被应用,用户看到的是 rails 应用程序的登录表单,而不是 web 应用程序:
http://localhost:3000/users/password/edit?redirect_url=http://localhost:8080/reset_password&reset_password_token=...
如果我评论该行devise_for :users
,则电子邮件链接是正确的,请使用api/auth/password/edit
:
http://localhost:3000/api/auth/password/edit?redirect_url=http://localhost:8080/reset_password&reset_password_token=...
但是,当然,通过评论devise_for :users
我不能只使用 rails 应用程序(on http://localhost:3000/users/sign_in
)登录。