[Django]-How to customize the payload section of the JWT response

3👍

JWT_RESPONSE_PAYLOAD_HANDLER
Responsible for controlling the response data returned after login or refresh. Override to return a custom response such as including the serialized representation of the User.

Defaults to return the JWT token.

Example:

def jwt_response_payload_handler(token, user=None, request=None):
    return {
        'token': token,
        'user': UserSerializer(user).data
    }

Default is {'token': token}

Leave a comment