Skip to content

Commit d1412c4

Browse files
refactor(serializers): Correct validation order in TokenRefreshSerializer
1 parent 35bcde7 commit d1412c4

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

rest_framework_simplejwt/serializers.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -114,23 +114,6 @@ def validate(self, attrs: dict[str, Any]) -> dict[str, str]:
114114

115115
data = {"access": str(refresh.access_token)}
116116

117-
if api_settings.ROTATE_REFRESH_TOKENS:
118-
if api_settings.BLACKLIST_AFTER_ROTATION:
119-
try:
120-
# Attempt to blacklist the given refresh token
121-
refresh.blacklist()
122-
except AttributeError:
123-
# If blacklist app not installed, `blacklist` method will
124-
# not be present
125-
pass
126-
127-
refresh.set_jti()
128-
refresh.set_exp()
129-
refresh.set_iat()
130-
refresh.outstand()
131-
132-
data["refresh"] = str(refresh)
133-
134117
# We handle user-related validation in a single, efficient block.
135118
user_id = refresh.payload.get(api_settings.USER_ID_CLAIM, None)
136119
if user_id:
@@ -170,6 +153,23 @@ def validate(self, attrs: dict[str, Any]) -> dict[str, str]:
170153
code="password_changed",
171154
)
172155

156+
if api_settings.ROTATE_REFRESH_TOKENS:
157+
if api_settings.BLACKLIST_AFTER_ROTATION:
158+
try:
159+
# Attempt to blacklist the given refresh token
160+
refresh.blacklist()
161+
except AttributeError:
162+
# If blacklist app not installed, `blacklist` method will
163+
# not be present
164+
pass
165+
166+
refresh.set_jti()
167+
refresh.set_exp()
168+
refresh.set_iat()
169+
refresh.outstand()
170+
171+
data["refresh"] = str(refresh)
172+
173173
return data
174174

175175

0 commit comments

Comments
 (0)