Skip to content
Advertisement

After login the `rest-auth`, how to return more information?

I use django-rest-auth in my Django project.

After login the rest-auth/login/, how to return more information?

In the rest-auth/login/, when I login the user, it returns a key.

enter image description here

I want to also return the user’s information, how can I get this?

Advertisement

Answer

At last, I get my solution:

class TokenSerializer(serializers.ModelSerializer):
    """
    Serializer for Token model.
    """
    user = UserInfoSerializer(many=False, read_only=True)  # this is add by myself.
    class Meta:
        model = TokenModel
        fields = ('key', 'user')   # there I add the `user` field ( this is my need data ).

In the project settings.py, add the TOKEN_SERIALIZER like bellow:

REST_AUTH_SERIALIZERS = {
    ...
    'TOKEN_SERIALIZER': 'Project.path.to.TokenSerializer',
}

Now I get my need data:

enter image description here

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement