我正在构建devise token auth gem
使用令牌进行身份验证的 Rails API。每当我尝试通过单击忘记密码来重置密码时,表单似乎会提供电子邮件,当给出电子邮件时,会向用户提供重置链接,并且他们在此前端页面上提交表单,该页面会发送API: PUT /auth/password
带有密码的请求和password_confirmation 参数。之后,我得到一个错误说Completed 401 Unauthorized
。
这是我的代码
function regeneratePassword(response, password, confirmPassword) {
const requestOptions = {
method: 'PUT',
headers: {
'Content-Type': 'application/json',
'access-token': response.headers['access-token'],
'client': response.headers['client'],
'token-type': response.headers['token-type'],
'uid': response.headers['uid'],
'expiry': response.headers['expiry']
},
body: JSON.stringify({"password": password, "password_confirmation": confirmPassword})
};
return fetch(`${baseURL.URL}${baseURL.PORT}/auth/password/`, requestOptions).then(handleResponse);
}
我在终端中遇到的错误:
Started PUT "/auth/password/" for ::1 at 2018-03-20 11:06:28 +0545
Processing by DeviseTokenAuth::PasswordsController#update as */*
User Load (1.6ms) SELECT "users".* FROM "users" WHERE "users"."uid" = $1 LIMIT $2 [["uid", "manager2@gmail.com"], ["LIMIT", 1]]
CACHE User Load (0.0ms) SELECT "users".* FROM "users" WHERE "users"."uid" = $1 LIMIT $2 [["uid", "manager2@gmail.com"], ["LIMIT", 1]]
[active_model_serializers] Rendered ActiveModel::Serializer::Null with Hash (0.12ms)
Completed 401 Unauthorized in 7ms (Views: 1.6ms | ActiveRecord: 1.7ms)