Reputation: 375
I am using Django with React and I am able to login the user with http://127.0.0.1:8000/rest-auth/login/' and register user with http://127.0.0.1:8000/rest-auth/registration/
I am trying to get the current user:
axios.get('http://127.0.0.1:8000/rest-auth/user/')
.then(res => {
console.log(res)
})
But I am getting the following error:
GET http://127.0.0.1:8000/rest-auth/user/ 403 (Forbidden)
I also tried it on postman and I get the following:
{
"detail": "Authentication credentials were not provided."
}
Can someone show me the correct way to do it? Thanks in advance.
Upvotes: 0
Views: 727
Reputation: 3104
This is because your route needs Authorization token
.
axios.get('http://127.0.0.1:8000/rest-auth/user/, {
headers: {'Authorization': "Bearer " + token}
})
.then(res => {
console.log(res)
})
Upvotes: 1