Search code examples
djangopython-3.xdjango-rest-frameworkauthorizationdjango-rest-auth

how to receive username with token by django rest authetication?


I am using django Django=2.1.7 and rest framework djangorestframework=3.9.2 This is my url for login

path('rest-auth/login', include('rest_auth.urls')),

When I enter username and password I got the token from rest API. But I want my user detail like name, id etc to show in my react components. Please help me how to achieve. I have seen many answers on StackOverflow even the official documentation is not descriptive https://www.django-rest-framework.org/api-guide/authentication/#tokenauthentication


Solution

  • If you use rest-auth you can get the id, username, email, first_name and last_name of the logged user using this URL: http://localhost:8000/rest-auth/user/