简体   繁体   English

如何使用 devise_token_auth 跳过 email 确认?

[英]how to skip email confirmation using devise_token_auth?

I'm using devise_token_auth gem for my Rails app.我正在为我的 Rails 应用程序使用 devise_token_auth gem。 I want to login into application once the user sign_up is done.我想在用户注册完成后登录应用程序。 How can I skip confirmation.我怎样才能跳过确认。

I tried config.reconfirmable = false but no luck我试过config.reconfirmable = false但没有运气

Can anyone suggest me or help me how can I achieve this?谁能建议我或帮助我如何实现这一目标? I tried the solution provided我尝试了提供的解决方案

Why won't Devise allow unconfirmed users to login even when allow_unconfirmed_access_for is set? 为什么即使设置了 allow_unconfirmed_access_for,Devise 也不允许未经确认的用户登录? But still ending up with但仍然以

{"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"]}

Add the following callback the model definition: 在模型定义中添加以下回调:

before_save -> { skip_confirmation! }

And remove :confirmable from included devise modules: 并从随附的devise模块中删除:confirmable

  devise :database_authenticatable, :recoverable,
         :trackable, :validatable, :registerable,
         :omniauthable # there is no :confirmable here

Alternatively, if you want to skip sending email confirmation for some people but keep sending it for other (based on email address for example) you can do something like that. 另外,如果您想跳过向某些人发送电子邮件确认但继续向其他人发送电子邮件确认(例如基于电子邮件地址),则可以执行类似的操作。

# 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

Tested on Rails 5.1.6 and Devise Token Auth 0.2.0 在Rails 5.1.6和Devise Token Auth 0.2.0上测试

In case someone has this error, include DeviseTokenAuth::Concerns::User should be after devise:database_authenticable... https://github.com/lynndylanhurley/devise_token_auth/issues/397#issuecomment-166113011如果有人出现此错误, 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM