Compare commits

..

2 commits

Author SHA1 Message Date
eb5e35df0a
Fix: Set corret api apps url prefix 2025-02-08 17:38:13 +01:00
6ca01d7bdf
Move: auth to new api seperate app 2025-02-08 17:36:36 +01:00
6 changed files with 40 additions and 8 deletions

View file

View file

@ -0,0 +1,6 @@
from django.apps import AppConfig
class ApiConfig(AppConfig):
default_auto_field = "django.db.models.BigAutoField"
name = "api.authentication"

View file

@ -0,0 +1,14 @@
from django.urls import path
from rest_framework_simplejwt.views import (
TokenObtainPairView,
TokenRefreshView,
)
from api.authentication.views import LogoutView
urlpatterns = [
path("logout/", LogoutView.as_view(), name="logout"),
path("token/", TokenObtainPairView.as_view(), name="token_obtain_pair"),
path("token/refresh/", TokenRefreshView.as_view(), name="token_refresh"),
]

View file

@ -0,0 +1,18 @@
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
# Logout View
class LogoutView(APIView):
permission_classes = [IsAuthenticated]
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)

View file

@ -1,12 +1,6 @@
from django.urls import path, include from django.urls import path, include
from rest_framework_simplejwt.views import (
TokenObtainPairView,
TokenRefreshView,
)
urlpatterns = [ urlpatterns = [
path("api/user/", include("api.user.urls")), path("auth/", include("api.authentication.urls")),
path("api/token/", TokenObtainPairView.as_view(), name="token_obtain_pair"),
path("api/token/refresh/", TokenRefreshView.as_view(), name="token_refresh"),
] ]

View file

@ -20,6 +20,6 @@ from django.urls import include, path
urlpatterns = [ urlpatterns = [
path("admin/", admin.site.urls), path("admin/", admin.site.urls),
path("", include("api.urls")), path("api/", include("api.urls")),
path("", include("images.urls")), path("", include("images.urls")),
] ]