There is an endpoint for getting the current user, “/auth/users/me”, just that we need to add our access token in the header of that request. We can do that with a browser extension called ModHeader or with postman. Using postman, key=Authorization and the value starts with “JWT” before our actual token.
When we make this get request, it only returns the current users id, username and email. But what if we want to return their first_name and last_name. We can do that by creating a custom serializer, also in the core app. see below
from djoser.serializers import UserSerializer as BaseUserSerializer
class UserSerializer(BaseUserSerializer): class Meta(BaseUserSerializer.Meta): fields = ['id', 'username', 'email', 'first_name', 'last_name']And then add the serializer to settings. see below
DJOSER = { 'SERIALIZERS': { 'user_create': 'core.serializers.UserCreateSerializer', 'current_user': 'core.serializers.UserSerializer' # current user }}Now when we make the get request with the header, it will return all the fields we have specified in our custom user serializer above.