1
votes

I am using React and Django rest framework for a project. I use Django rest framework simple JWT for authentication. Now, I want to display the username in the navbar after the user logs in. So, is there a way in simple JWT for returning user details from the access token generated after authentication, just like Djoser returns user credentials when supplied the access token?

Sorry if this question is silly but I was not able to find a solution to this anywhere.

1
Must have missed that. Thank you so much!srijan sankrit
Hey, @Aprimus that page just tells about how to customise the tokens. My question was if there is a pre-built function in simple JWT which helps in extracting claims from token or do I have to do it myself?srijan sankrit

1 Answers

2
votes

if you want to obtain the information of the owner of the token you can consult it in REQUEST.

class ViewProtect(APIView):
    permission_classes = [permissions.IsAuthenticatedOrReadOnly]

    def post(self, request, format=None):
        token_user_email = request.user.email
        token_user_username = request.user.username
        pass