I am building rails API using devise token auth gem
for authentication using tokens.
Whenever I try to reset a password by clicking Forget Password, the form appears to provide email, when email is given then reset link is given to the user and they submit the form on this frontend page, which sends a request to API: PUT /auth/password
with the password and password_confirmation parameters.After that, I got an error saying Completed 401 Unauthorized
.
Here is my code
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);
}
Error I got in terminal:
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)