4

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)
shreejana
  • 391
  • 3
  • 20
  • if you update your contoller code, more easily find the cause. plz check the list 1. can you see the access-token in request header from controller? 2. before password changing, was completed to authenticate a user by access-token? 3. exists the user ? 4. is user activate? – ogelacinyc Mar 26 '18 at 12:22

0 Answers0