簡體   English   中英

如何使用 devise_token_auth 跳過 email 確認?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM