设计不会通过登录显示正确的错误
问题描述:
我在后端使用devise
和devise-token-auth
进行身份验证,在客户端使用'redux-auth`。设计不会通过登录显示正确的错误
我试图让设计发送正确的错误信息展现给客户端的情况下,账户被暂时锁定
这是我的user.rb
文件
# devise method to check if user is banned
def active_for_authentication?
super && !self.banned?
end
# message to send in case of ban. doesnt work yet
def inactive_message
self.banned? ? :locked : super
end
def banned?
return self.role == 'banned'
end
我devise.en.yml
文件
en:
devise:
confirmations:
confirmed: "Your email address has been successfully confirmed."
failure:
locked: "Your account is locked."
errors:
messages:
locked: "Your account has been banned"
我试图用redux-auth或CURL登录时似乎得到了设计的标准错误响应(我无法看到在devise.en.yml
文件的任何地方找到了给定的消息)
curl http://localhost:3000/auth/sign_in -d "[email protected]&password=123"
响应
{"success":false,"errors":["A confirmation email was sent to your account at '[email protected]'."]}
我在哪里可以自定义消息?
答
该消息是在devise_token_auth YAML文件:https://github.com/lynndylanhurley/devise_token_auth/blob/123cfb730ebaf4e2acc124edd39e68816cb0b8cf/config/locales/en.yml
,所以你需要通过添加以下到您的本地YAML文件中的一个来覆盖它:
en:
devise_token_auth:
sessions:
not_confirmed: "Custom message"
谢谢,这个工作 – Kannaj