Skip to content

Commit 0d1678c

Browse files
authored
added session authentication
When I log out from the API it does not redirect from login back and cannot reload it so for again login in this project terminate the server and run again so I try to solve this problem using session authentication, Now it's working fine after logout its redirect to login does not need to stop the server and run again.
1 parent c11620e commit 0d1678c

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

rest_api/views.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from .serializers import BucketlistSerializer, UserSerializer
44
from .models import Bucketlist
55
from django.contrib.auth.models import User
6-
6+
from rest_framework.authentication import SessionAuthentication
77

88
class CreateView(generics.ListCreateAPIView):
99
"""This class handles the GET and POSt requests of our rest api."""
@@ -12,6 +12,7 @@ class CreateView(generics.ListCreateAPIView):
1212
permission_classes = (
1313
permissions.IsAuthenticated,
1414
IsOwner)
15+
authentication_classes = [SessionAuthentication]
1516

1617
def perform_create(self, serializer):
1718
"""Save the post data when creating a new bucketlist."""
@@ -26,15 +27,18 @@ class DetailsView(generics.RetrieveUpdateDestroyAPIView):
2627
permission_classes = (
2728
permissions.IsAuthenticated,
2829
IsOwner)
30+
authentication_classes = [SessionAuthentication]
2931

3032

3133
class UserView(generics.ListAPIView):
3234
"""View to list the user queryset."""
3335
queryset = User.objects.all()
3436
serializer_class = UserSerializer
37+
authentication_classes = [SessionAuthentication]
3538

3639

3740
class UserDetailsView(generics.RetrieveAPIView):
3841
"""View to retrieve a user instance."""
3942
queryset = User.objects.all()
4043
serializer_class = UserSerializer
44+
authentication_classes = [SessionAuthentication]

0 commit comments

Comments
 (0)