We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
for_user
1 parent c1231af commit 1ad763bCopy full SHA for 1ad763b
docs/creating_tokens_manually.rst
@@ -6,11 +6,19 @@ Creating tokens manually
6
Sometimes, you may wish to manually create a token for a user. This could be
7
done as follows:
8
9
+.. warning::
10
+ The ``for_user`` method does not check if the user is active. If you need to verify the user's status,
11
+ this check needs to be done before creating the tokens.
12
+
13
.. code-block:: python
14
15
from rest_framework_simplejwt.tokens import RefreshToken
16
+ from rest_framework_simplejwt.exceptions import AuthenticationFailed
17
18
def get_tokens_for_user(user):
19
+ if not user.is_active:
20
+ raise AuthenticationFailed("User is not active")
21
22
refresh = RefreshToken.for_user(user)
23
24
return {
0 commit comments