hey guys, I hope you're doing well. I'm reaching out because I've encountered an issue with my Djang...
f
hey guys, I hope you're doing well. I'm reaching out because I've encountered an issue with my Django application that involves the @verify_session() decorator provided by SuperTokens. Here's a snippet of my code:
r
hey @fayzul_ whats the import statement for verify_session?
f
from supertokens_python.recipe.session.framework.django.asyncio import verify_session
r
@KShivendu can help here.
k
hey @fayzul_ for some reason, I can't see your snippet. Can you please share again?
k
Hmm. It worked seamlessly for me. Can you try creating a simpler view and see if it works for you. for example, try this:
Copy code
from supertokens_python.recipe.session.framework.django.asyncio import verify_session as averify_session

import asyncio

@averify_session()
async def async_api(request):
    await asyncio.sleep(2)
    return JsonResponse({"message": "Hello world"})
@fayzul_ ^
f
hello @KShivendu
i appreciate your response
unfortunately that didnt seem to work
i still got the same error
although
k
few questions: - how are you running the server? - python version - django version
f
i used the verify_session middleware to get data in another view and that works
let me quickly check those for u
python = 3.10.11
k
> verify_session middleware to get data in another view and that works didn't get you. Do you mean that if you use it in a view that doesn't use
sync_to_async
then it works?
f
sorry for the vague explanation. no, i mean i use the function with everything. the likes of sync_to_async and verify_session and it works
let me send a code snippet so you can see
Copy code
def fetch_invites(user_email):
    student = Student.objects.get(student_id=user_email)
    student_interests = student.interests.all()
    tInvites = Invites.objects.filter(inviteInterest__in=student_interests).distinct()
    response_data = [{
        'inviteName': invite.inviteName,
        'inviteDescription': invite.inviteDescription,
        'inviteLocation': invite.inviteLocation,
        'inviteDate': invite.inviteDate,
        # Add other fields as needed
    } for invite in tInvites]
    return response_data

@verify_session()
async def getUserInvites(request):
    session: SessionContainer = request.supertokens
    user_id = session.get_user_id()
    user = await get_user_by_id(user_id)
    user_email = user.email

    response_data = await sync_to_async(fetch_invites)(user_email)

    return JsonResponse(response_data, safe=False)
django version = 4.2.4
im running the server normally.
not using any asgi configs
i think i found the issue
one of the functions i use
uses verify function and works perfect
but this one
doesn’t and return the awaiting error
the main difference is the GET and POST methods used in both of them
maybe i have not configured sometimes to use verify_session with POST methods?
r
there is nothing specific that needs to be done for post vs get
f
oh
okay
so is there anything that can explain why it works for get but not for post?
r
not quite sure.
but it's most lilekely in your code
f
okay
i’ll look into it and provide you with an update
many thanks
i found the issue
it was middlewares arguing
at the beginning of the function i had put in two decorators
but i should have put the verify_session decorator first
like so
Copy code
@verify_session()
@csrf_exempt
#@api_view(['POST'])
async def create_community(request):
    rest of code
r
Great!
f
👍🏾