2017-09-21 4 views
2

devise_token_auth 보석을 사용하면 this question과 비슷하게 json 응답에서 두 번 나타나는 유효성 검사 오류!? 로그에서Rails 5.1 : devise_token_auth는 1을 찾았을 때 2 개의 에러를 반환합니다.

다음 unpermitted_parameters 라인이 두 번 표시되어 있는지

Processing by DeviseTokenAuth::RegistrationsController#create as JSON 
    Parameters: {"name"=>"Mickey Mouse", "email"=>"[email protected]", "password"=>"[FILTERED]", "confirmPassword"=>"[FILTERED]", "confirm_success_url"=>"http://localhost:4200/register", "registration"=>{"name"=>"Mickey Mouse", "email"=>"[email protected]", "password"=>"[FILTERED]", "confirmPassword"=>"[FILTERED]", "confirm_success_url"=>"http://localhost:4200/register"}} 
Unpermitted parameters: :confirmPassword, :confirm_success_url, :registration 
Unpermitted parameters: :confirmPassword, :confirm_success_url, :registration 
    (0.2ms) BEGIN 
    User Exists (0.9ms) SELECT 1 AS one FROM "users" WHERE "users"."email" = $1 LIMIT $2 [["email", "[email protected]"], ["LIMIT", 1]] 
    (0.8ms) SELECT COUNT(*) FROM "users" WHERE "users"."provider" = $1 AND "users"."email" = $2 [["provider", "email"], ["email", "[email protected]"]] 
    (0.3ms) ROLLBACK 
Completed 422 Unprocessable Entity in 247ms (Views: 0.7ms | ActiveRecord: 6.9ms) 

공지 사항 - (그 선이 우편 배달을 통해 표시되지 않습니다) 뭔가 이상한을 나타내는 것으로 보인다.

내 사용자 모델에는 표준 가이드가 추가되어 있지 않으므로 모델에 고유성 또는 존재 확인이 2 가지가 아니며 보석의 소스 코드를 조사해도 그 사실이 나타나지 않습니다.

{ 
    "status": "error", 
    "data": { 
     "id": null, 
     "account_id": null, 
     "provider": "email", 
     "uid": "", 
     "name": null, 
     "nickname": null, 
     "image": null, 
     "email": "[email protected]", 
     "created_at": null, 
     "updated_at": null 
    }, 
    "errors": { 
     "email": [ 
      "has already been taken", 
      "has already been taken" 
     ], 
     "full_messages": [ 
      "Email has already been taken", 
      "Email has already been taken" 
     ] 
    } 
} 

레일즈 API가 Angular2에서

라고 :

class User < ActiveRecord::Base 

    # Include default devise modules. 
    devise :database_authenticatable, :registerable, 
      :recoverable, :rememberable, :trackable, :validatable, 
      :confirmable, :omniauthable 
    include DeviseTokenAuth::Concerns::User 
end 

나는 우체부에서이 엔드 포인트를 호출 할 경우, 나는이 같은 결과를 얻을 수는 여기에 반환 된 JSON입니다 : 여기

모델입니다 angular2-token 라이브러리를 사용하지만 분명히 문제는 아닙니다 (우편 배달부의 결과 제공).

이 오류의 원인을 어떻게 알 수 있습니까? 2 번째 오류를 제거하기 위해 어떻게 원숭이 패치를 할 수 있습니까? 내가 모델에서 :validatable을 제거하고 내 자신의 유효성 검사를 넣으면

UPDATE

는 :

validates_uniqueness_of :email 

을 나는 이상한 동일한 결과를 얻을.

+0

그것은 이상한 것이 아니지만'uniq' 오류 메시지 배열을 사용하기 전에. – pdoherty926

+0

@ pdoherty926 이것은 보석 상자 위에 만들어진 보석에있는 것을 제외하고는 그렇게하고 싶습니다. 그리고 나는 어떻게 든 원숭이 패치를함으로써 장치 등록 컨트롤러에서 그들에게 접근 할 수있는 방법을 알아 내야 할 것입니다. 친절한 (전에는 한 번도 해본 적이 없어) – rmcsharry

답변

2

편집 :이 문제 당신의 보석을 업그레이드 고정되었습니다! > v0.1.43.beta1


내가 the issue 발견은 GitHub의에보고됩니다.

해결 방법은 제거하는 것입니다 : validatable (이메일 고유성은 여전히 ​​불 것)하고 암호 확인을 위해 자신의 검증을 롤 (stephanebruckert에 의해 거기에 응답 참조) 그 문제에 표시된 여기에 재현 같이

견적 : "validatable는 전자 메일과 암호의 유효성을 검사하므로 모델에 포함되어 있지 않아야합니다. 그렇지 않으면 두 번 유효성이 검사됩니다. 필자의 경우 전자 메일은 두 번 유효성이 검사되는 반면, 내 모델에서 추가 유효성 검사를 수행 했으므로 유효성 검사를 제거하고 암호 및 password_confirmation에 대한 자체 유효성 검사를 완료했습니다. "

validates_presence_of :password, on: :create 
    validates :password, 
    length: { minimum: 8 }, 
    allow_blank: true 
    validate :password_complexity 
    validates_confirmation_of :password 
    validates_presence_of :password_confirmation, if: lambda {| u| u.password.present? } 

    private 

    def password_complexity 
     return unless password 
     if password.include?(username) || !password.match(/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)./) 
     errors.add(:password, "Must include at least one lowercase letter, one uppercase letter and one digit") 
     end 
    end 

중복 된 전자 메일 오류는 해결되지만 다음은 토끼 구멍이 this issue을 발견하게하는 'password_confirmation은 공백 일 수 없습니다.'오류가 발생합니다.기본적으로 모든 내용을 읽어야하지만, API는 이 아닙니다.은 암호 확인 값 (양식 자체에만 필요함)을 적용해야합니다 :)

+1

답변에 해결 방법의 내용을 자유롭게 복사하십시오! https://github.com/lynndylanhurley/devise_token_auth/issues/892#issuecomment-309425198 –

+0

@ StéphaneBruckert 좋은 생각, 끝났습니다 :) – rmcsharry