diff --git a/wtnt/user/auth/service.py b/wtnt/user/auth/service.py index 503d7fe..4788c0c 100644 --- a/wtnt/user/auth/service.py +++ b/wtnt/user/auth/service.py @@ -55,12 +55,16 @@ def process_response_data(self, response_data): return response_data, access_token def logout(self): - _, access_token = self.request.META.get("HTTP_AUTHORIZATION").split(" ") - try: - user_id = AccessToken(access_token, verify=False).payload.get("user_id") - except TokenError: - raise token_exception.InvalidTokenError() - RedisUtils.delete_refresh_token(user_id) + authorization = self.request.META.get("HTTP_AUTHORIZATION", None) + if authorization: + _, access_token = authorization.split(" ") + try: + user_id = AccessToken(access_token, verify=False).payload.get("user_id") + except TokenError: + raise token_exception.InvalidTokenError() + RedisUtils.delete_refresh_token(user_id) + else: + token_exception.NoTokenInAuthorizationHeaderError() class RegisterService(BaseService): diff --git a/wtnt/user/auth/views.py b/wtnt/user/auth/views.py index 4cb5b7a..358529f 100644 --- a/wtnt/user/auth/views.py +++ b/wtnt/user/auth/views.py @@ -3,7 +3,7 @@ from rest_framework.views import APIView from rest_framework.request import Request from rest_framework.response import Response -from rest_framework.permissions import AllowAny, IsAuthenticated +from rest_framework.permissions import AllowAny from rest_framework import status from rest_framework_simplejwt.views import TokenRefreshView from dj_rest_auth.registration.views import SocialLoginView @@ -46,8 +46,6 @@ def post(self, request, *args, **kwargs): class LogoutView(APIView): - permission_classes = [IsAuthenticated] - def post(self, request, *args, **kwargs): auth_service = AuthService(request) auth_service.logout()