Closed davidnierman closed 2 years ago
change this line:
Authorization: `Token token=${user.token}`
to this:
Authorization: `Token ${user.token}`
inside your changePassword function.
Wow that was it! - so why do my other requests work using the original way? - such as signout
export const signOut = (user) => {
return axios({
url: apiUrl + '/sign-out/',
method: 'DELETE',
headers: {
Authorization: `Token token=${user.token}`,
},
})
}
// somehow this is not sending authorization over correctly
export const changePassword = (passwords, user) => {
return axios({
url: apiUrl + '/change-password',
method: 'PATCH',
headers: {
Authorization: `Token ${user.token}`,
},
data: {
passwords: {
old: passwords.oldPassword,
new: passwords.newPassword,
},
},
})
}
Are you certain that the signOut is working? because it shouldn't be reading that token, change it to the other syntax.
What broke the sign in route and how? you don't need to pass a user to sign in since you don't need the token
turns out the sign in route broke because I accidentally typed something and saved it when I thought I was in a different screen. git diff
helped me figure that out.
But yeah the signout route works with this Authorization:
Token token=${user.token},
it shouldn't so that should be changed
What stack are you using?
(ex: MERN(mongoose + react), DR(django + react), PEN, etc.)
DR
What's the problem you're trying to solve?
Change Password Request Keeps Throwing 401 - Unauthorized Error
Post any code you think might be relevant (one fenced block per file)
Client Side
App.js
ChangePassword.js
auth.js
Server Side
urls.py
user_views.py
serializer.py
If you see an error message, post it here. If you don't, what unexpected behavior are you seeing?
from console.log client side:
xhr.js:210 PATCH http://localhost:8000/change-password 401 (Unauthorized)
from server side CLI/TERMINAL:
Unauthorized: /change-password [27/Apr/2022 05:21:03] "PATCH /change-password HTTP/1.1" 401 27
What is your best guess as to the source of the problem?
I have no idea. I pulled the whole request apart from the data to the user and auth...
Here is what I know:
The request works in Postman. The request does not work within the browser.. --> I think this rules out that it is an server/api issue
If I take the token from the browser login session and use it in Postman it works --> I think this rules out it is token issue
For some reason the 401 error is thrown BEFORE the rest of user_views.py's
class ChangePassword(generics.UpdateAPIView):
and its functiondef partial_update(self, request):
is ran. --> I know this based on adding print() statementsWhat things have you already tried to solve the problem?
I have console.logged and printed everything I could possibly think of.
I have looked up django documentation for the class that is inherited by ChangePassword class in user_views: updateapiview - > I am convinced it is not api/servicer side since it works on postman, but looked this up anyways
I have checked my serializer too to cross my t's and dot my i's
On the client side I have compared the axios request to the other user/auth requests and tested the other ones. All of them work except updatepassword..
Paste a link to your repository here
composting-mgmt-systems composting-mgmt-systems-api