In Python, is @verify_session() the only way to ve...
# support-questions
c
In Python, is @verify_session() the only way to verify a session? I'm having some trouble in a function:
Copy code
class DonationViewSet(viewsets.ModelViewSet):
    queryset = Donation.objects.all()
    serializer_class = DonationSerializer

    @verify_session()
    async def get_queryset(self):
        session: SessionContainer = self.request.supertokens
        user_id = session.get_user_id()
        return Donation.objects.filter(user_id_id=user_id)
'coroutine' object is not iterable edit 1 I fixed this problem, I had to import verify_session from syncio, not asyncio, and remove the async keyword, but I got into another problem: verify_session is looking for the parameter request, but it is inside 'self' edit 2 I copied the implementetion of verify_session for Django, and it works edit 3 The best solution I found was creating another function inside the function to verify the session and return it (with @verify_session()), much cleaner
Copy code
class DonationViewSet(viewsets.ModelViewSet):
    queryset = Donation.objects.all()
    serializer_class = DonationSerializer

    def get_queryset(self):
        @verify_session()
        def verify(request):
            return request.supertokens

        session = verify(self.request)
        user_id = session.get_user_id()
        return Donation.objects.all(user_id_id=user_id)
I wrote this process, for everyone using Django REST framework like in my case.