File add-warning.patch of Package python-djangorestframework-simplejwt.19207
From a649aeb080dc11f1ee38a36905b90c582a737978 Mon Sep 17 00:00:00 2001
From: Vjeran Grozdanic <vjeran.grozdanic@sentry.io>
Date: Wed, 26 Feb 2025 23:01:34 +0100
Subject: [PATCH] docs: Add warning in docs for `for_user` usage
---
docs/creating_tokens_manually.rst | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/docs/creating_tokens_manually.rst b/docs/creating_tokens_manually.rst
index 5c42b0cee..8dc5caa04 100644
--- a/docs/creating_tokens_manually.rst
+++ b/docs/creating_tokens_manually.rst
@@ -6,11 +6,19 @@ Creating tokens manually
Sometimes, you may wish to manually create a token for a user. This could be
done as follows:
+.. warning::
+ The ``for_user`` method does not check if the user is active. If you need to verify the user's status,
+ this check needs to be done before creating the tokens.
+
.. code-block:: python
from rest_framework_simplejwt.tokens import RefreshToken
+ from rest_framework_simplejwt.exceptions import AuthenticationFailed
def get_tokens_for_user(user):
+ if not user.is_active:
+ raise AuthenticationFailed("User is not active")
+
refresh = RefreshToken.for_user(user)
return {