![](/img/trans.png)
[英]devise_token_auth - skip_confirmation_notification! not working
[英]how to skip email confirmation using devise_token_auth?
我正在为我的 Rails 应用程序使用 devise_token_auth gem。 我想在用户注册完成后登录应用程序。 我怎样才能跳过确认。
我试过config.reconfirmable = false
但没有运气
谁能建议我或帮助我如何实现这一目标? 我尝试了提供的解决方案
为什么即使设置了 allow_unconfirmed_access_for,Devise 也不允许未经确认的用户登录? 但仍然以
{"success":false,"errors":["A confirmation email was sent to your account at test123@gmail.com. You must follow the instructions in the email before your account can be activated"]}
在模型定义中添加以下回调:
before_save -> { skip_confirmation! }
并从随附的devise模块中删除:confirmable
:
devise :database_authenticatable, :recoverable,
:trackable, :validatable, :registerable,
:omniauthable # there is no :confirmable here
另外,如果您想跳过向某些人发送电子邮件确认但继续向其他人发送电子邮件确认(例如基于电子邮件地址),则可以执行类似的操作。
# app/models/user.rb
after_create :skip_confirmation_email_for_some_user
# ...
protected
def skip_confirmation_email_for_some_user
if self.email.include? "noconfirm"
self.skip_confirmation!
self.confirm
end
end
在Rails 5.1.6和Devise Token Auth 0.2.0上测试
如果有人出现此错误, include DeviseTokenAuth::Concerns::User
should be after devise:database_authenticable...
https://github.com/lynndylanhurley/devise_token_auth/issues/397#issuecomment-166113011
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.