Skip to content
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

Added a request.auth check to logout to avoid false success message when no token is passed #601

Merged
merged 2 commits into from
Mar 24, 2024
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
5 changes: 5 additions & 0 deletions dj_rest_auth/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,11 @@ def post(self, request, *args, **kwargs):
return self.logout(request)

def logout(self, request):
if not (request.auth or api_settings.USE_JWT or api_settings.SESSION_LOGIN):
return Response(
{'detail': _('You should be logged in to logout. Check whether the token is passed.')},
status=status.HTTP_400_BAD_REQUEST,
)
try:
request.user.auth_token.delete()
except (AttributeError, ObjectDoesNotExist):
Expand Down