簡體   English   中英

Rails Knock jwt配置多個參數來登錄實體模型

[英]Rails Knock jwt config more than one param to login on the entity model

在設置了一個簡單的認證后,我想向auth_params添加一個額外的參數,

在文檔中,配置是通過實體模型

    def self.from_token_request request
    # Returns a valid user, `nil` or raise `Knock.not_found_exception_class_name`
    # e.g.
    #   email = request.params["auth"] && request.params["auth"]["email"]
    #   self.find_by email: email
  end

所以我想是這樣

def self.from_token_request(request)
    email = request.params["auth"] && request.params["auth"]["email"]
    confirmation_email = request.params["auth"] && request.params["auth"]["confirmation_email"]
    self.find_by(email: email, confirmation_email: confirmation_email)
  end

並且在配置到的UserTokenController的帖子之后

def auth_params
    params.require(:auth).permit(:email, :password, :confirmation_email)
  end

沒有生成令牌,也沒有使用:confirmation_email參數並導致404錯誤!

日志

由UserTokenController#create作為/參數處理:{“ auth” => {“ password” =>“ [FILTERED]”,“ email” =>“ manolo@manolo.com”},“ user_token” => {“ auth” => {“密碼” =>“ [已過濾]”,“電子郵件” =>“ manolo@manolo.com”}}}用戶負載(2.8毫秒)選擇“用戶”。*從“用戶”中查找“用戶”。 “ email” = $ 1 AND“ users”。“ confirmation_email”是NULL LIMIT $ 2 [[“ email”,“ manolo@manolo.com”],[“ LIMIT”,1]]↳app / models / user.rb:51 96ms內完成404找不到(ActiveRecord:15.3ms)

因此,請有人可以闡明如何配置敲門的gem以使用更多電子郵件參數進行登錄嗎?

我必須通過為連接添加第二個參數來測試代碼,它在我這一方面工作得很好,請在此處輸入圖片描述

def auth_params params.permit auth: [:phone, :pin, :has_access] end

`def self.from_token_request

    phone = request.params[:auth]&& request.params[:auth][:phone]
  has_access= request.params[:auth]&& request.params[:auth][:has_access]
  self.find_by phone: phone, has_access: has_access

結束`

如果您已經提交了要約的報價。 我已收到建議以幫助您

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

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