Skip to content

Commit d20a601

Browse files
authored
Merge pull request #286 from Tivix/jwt-serializer-with-custom-user-model
JWT serializer with custom user model
2 parents f200b8d + ca62f44 commit d20a601

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

rest_auth/serializers.py

Lines changed: 12 additions & 3 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,12 +131,20 @@ class Meta:
130131
read_only_fields = ('email', )
131132

132133

134+
# Required to allow using custom USER_DETAILS_SERIALIZER in
135+
# JWTSerializer. Defining it here to avoid circular imports
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-
user = UserDetailsSerializer()
147+
user = JWTUserDetailsSerializer()
139148

140149

141150
class PasswordResetSerializer(serializers.Serializer):

0 commit comments

Comments
 (0)