Gallery-Archivist/backend/api/authentication/views.py

22 lines
710 B
Python
Raw Permalink Normal View History

2025-02-08 17:36:36 +01:00
from rest_framework.response import Response
from rest_framework.views import APIView
from rest_framework.permissions import IsAuthenticated
from rest_framework_simplejwt.tokens import RefreshToken
2025-02-10 09:32:34 +01:00
from api.authentication.serializers import LogoutSerializer
2025-02-08 17:36:36 +01:00
# Logout View
class LogoutView(APIView):
permission_classes = [IsAuthenticated]
2025-02-10 09:32:34 +01:00
serializer_class = LogoutSerializer
2025-02-08 17:36:36 +01:00
def post(self, request):
try:
refresh_token = request.data["refresh"]
token = RefreshToken(refresh_token)
token.blacklist()
return Response({"message": "Logout successful"})
except Exception as e:
return Response({"error": str(e)}, status=400)