0

I am trying to return the users id with the token after the user registers but only the token is being returned

I am using dj-rest-auth and docs say I can serialize extra fields with the RegisterSerializer

My serializer:

from dj_rest_auth.registration.serializers import RegisterSerializer


class CustomRegistrationSerializer(RegisterSerializer):
    user_id = serializers.SerializerMethodField('get_user_id')

    def get_user_id(self, obj):
        o = obj['username']
        user_id = User.objects.get(username=o).id
        print(user_id)
        return Response(user_id)

My settings:

REST_AUTH_REGISTER_SERIALIZERS = {
    'REGISTER_SERIALIZER': 'users.serializers.CustomRegistrationSerializer'
}

I am able to print the id in my console, but in the api response it's only returning the token and not the id

Appreciate any help! Don't know what I am doing wrong.

jdez
  • 189
  • 1
  • 10
  • Also, what is it that you're trying to do? – Tiago Martins Peres Jul 24 '22 at 00:57
  • 1
    I am trying to return the user id along with the token after i register, but only the token is returned. When i just do user_id i still am able to print the id but it's not getting returned with postman or my frontend – jdez Jul 24 '22 at 01:03
  • 1
    Found solution with this post: https://stackoverflow.com/a/44968470/16421620 – jdez Jul 24 '22 at 02:24

0 Answers0