Search code examples
djangodjango-rest-frameworkdjango-rest-auth

django-rest-auth unable to access user details page


I am using django-rest-auth to authenticate and register my user I can do everyhting.

Login is working Registration is working but I am unable to access get User details:

/rest-auth/user/ (GET, PUT, PATCH) 

I am trying to access this endpoint I am using JWT I am getting correct token. But when I am using this command in curl:

 curl -X GET http://localhost:8000/rest-auth/user/ -H 'Authorization: Bearer <jwt-toke>'

I am getting this error:

{"detail":"Authentication credentials were not provided."}

What do I need to do to access details of user


Solution

  • After a long investigation, I was able to find a solution and according to the documentation if you want to use JWT in django-rest-auth.

    They shared one link which is not working actual link is:

    https://jpadilla.github.io/django-rest-framework-jwt/
    

    After installing django-rest-auth.

    You need to install django-rest-framework-jwt using:

    pip install djangorestframework-jwt
    

    And it will work fine if you want to access this URL:

    /rest-auth/user/ (GET, PUT, PATCH) 
    

    You need to pass JWT instead of Bearer example:

     curl -X GET http://localhost:8000/rest-auth/user/ -H 'Authorization: JWT <jwt-toke>'
    

    And it worked for me.