Skip to content

docs: Add warning in docs for for_user usage #872

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 27, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions docs/creating_tokens_manually.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading