Skip to content

Commit dd6db35

Browse files
committed
Allow using custom UserDetailsSerializer with JWTSerializer - update
1 parent a907efc commit dd6db35

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

rest_auth/serializers.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@
66
from django.utils.translation import ugettext_lazy as _
77
from django.utils.encoding import force_text
88

9-
from .models import TokenModel
10-
119
from rest_framework import serializers, exceptions
1210
from rest_framework.exceptions import ValidationError
1311

12+
from .models import TokenModel
13+
from .utils import import_callable
14+
1415
# Get the UserModel
1516
UserModel = get_user_model()
1617

@@ -130,21 +131,20 @@ class Meta:
130131
read_only_fields = ('email', )
131132

132133

134+
# Required to allow using custom UserDetailsSerializer in
135+
# JWTSerializer
136+
rest_auth_serializers = getattr(settings, 'REST_AUTH_SERIALIZERS', {})
137+
JWTUserDetailsSerializer = import_callable(
138+
rest_auth_serializers.get('USER_DETAILS_SERIALIZER', UserDetailsSerializer)
139+
)
140+
141+
133142
class JWTSerializer(serializers.Serializer):
134143
"""
135144
Serializer for JWT authentication.
136145
"""
137146
token = serializers.CharField()
138-
139-
def __init__(self, *args, **kwargs):
140-
"""
141-
Need to add `user` field dynamically, to allow using
142-
custom UserDetailsSerializer
143-
"""
144-
from app_settings import UserDetailsSerializer
145-
146-
super(JWTSerializer, self).__init__(*args, **kwargs)
147-
self.fields['user'] = UserDetailsSerializer()
147+
user = JWTUserDetailsSerializer()
148148

149149

150150
class PasswordResetSerializer(serializers.Serializer):

0 commit comments

Comments
 (0)