Skip to content

Commit

Permalink
restore token deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
khvn26 committed Oct 3, 2024
1 parent e863d3d commit 1a0dc87
Showing 1 changed file with 5 additions and 11 deletions.
16 changes: 5 additions & 11 deletions api/custom_auth/jwt_cookie/views.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
from djoser.views import TokenDestroyView
from rest_framework.request import Request
from rest_framework.response import Response
from rest_framework.status import HTTP_204_NO_CONTENT
from rest_framework.views import APIView
from rest_framework_simplejwt.tokens import SlidingToken

from custom_auth.jwt_cookie.constants import JWT_SLIDING_COOKIE_KEY


class JWTSlidingTokenLogoutView(APIView):
"""
This view only invalidates the JWT cookie.
Currently, for clients which use token authentication, it's a no-op view.
"""

class JWTSlidingTokenLogoutView(TokenDestroyView):
def post(self, request: Request) -> Response:
response = Response(status=HTTP_204_NO_CONTENT)
if isinstance(request.auth, SlidingToken):
request.auth.blacklist()
response = super().post(request)
if isinstance(jwt_token := request.auth, SlidingToken):
jwt_token.blacklist()
response.delete_cookie(JWT_SLIDING_COOKIE_KEY)
return response

0 comments on commit 1a0dc87

Please sign in to comment.