Hey. got a question, im actually using supertokens...
# support-questions-legacy
d
Hey. got a question, im actually using supertokens throught the endpoints and rest to be able to use a flutter frontend, but for example when the access_token expires I get "500 Internal Server Error" I would like to see how can I get this error that im getting in my console?
r
Hey @dleiva04
This error should yield a 401. Not 500
You need to use our errorHandler
Are you using the verifySession function on the backend? Or getSession?
d
Im using the verifySession as a dependency
r
Can I see how? If you pass in an expired access token, it should result in a 401
Or even a missing access token
d
I want to use
Depends(verify_session())
in every endpoint
r
Right. And if you query this endpoint without an access token, what status code does it send back?
d
I got the 500
r
That’s odd. Which framework are you using?
d
FastApi
r
@KShivendu can help here.
Have you added our middleware to your app?
d
app.add_middleware(get_middleware())
this one?
from supertokens_python.framework.fastapi
r
Yes.
d
Then yes, I have in my main file
r
And it’s added before your routes run?
d
Yes, exactly
r
Hmm. This should work.
We will wait for @KShivendu to help out.
d
Thank you so much!
r
Can I see how you have done supertokens.init on the backend?
d
Yes
Let me show you
k
I'm getting 401 on calling routes protected with
verify_session()
in fastapi. So the SDK is fine. There should be some issue in the config. I'll try to replicate your setup now.
d
Thank you @KShivendu
just in case, this is the settings
k
Also, can you please confirm that
@router.patch("/{listing_id}")
works with valid access token? Do you get 200?
d
Oh yeah, is working properly
k
Great.
Give me some time to replicate your setup.
d
Yeah no problem, take your time, thanks for the help
k
Or maybe we can get on a call. Are you comfortable with that? Or should I just replicate it locally?
d
We can get into a call if you want
Im ok with that
k
great. can you join the voice channe?
and share your screen.
Copy code
@app.get("/sessioninfo")    
async def secure_api(s: SessionContainer = Depends(verify_session())):
    return {
        "sessionHandle": s.get_handle(),
        "userId": s.get_user_id(),
        "accessTokenPayload": s.get_access_token_payload(),
    }
Copy code
from supertokens_python.recipe.session import SessionContainer
Hey @dleiva04 let's get on quick call again.
d
Ok
k
/auth/signup/email/exists?email=test@example.com
Copy code
app = CORSMiddleware(
    app=app,
    allow_origins=[config.app_info.website_domain],
    allow_credentials=True,
    allow_methods=["GET", "PUT", "POST", "DELETE", "OPTIONS", "PATCH"],
    allow_headers=["Content-Type"] + get_all_cors_headers(),
)
bound method BaseHTTPMiddleware.call_next of <supertokens_python.framework.fastapi.fastapi_middleware.get_middleware.<locals>.Middleware object at 0x7f72d0a91550
d
Just FYI I try again in a simple appi with only supertokens in it and python version 3.8.15, im getting the same error
k
@dleiva04 What version of supertokens-python are you using?
Also how are you running the flask app? Something like:
Copy code
python
if __name__  == "__main__":
    uvicorn.run(app, host="0.0.0.0", port=3001)
d
supertokens-python 0.11.6
Its a fastapi, and no, im not running like that, i was running from the debugger
I saw that supertokens has version 0.11.12, so I upgrade it, but didnt work
And on my test environment I try with this and didnt work
k
Hey @dleiva04 can you please share your complete setup code? (remove any private credentials/code) I need to replicate this on my system.
You may share here or create a github repo.
d
That's my setup
Using python 3.8.15 and supertokens latest version (0.11.12)
Also, this is a fastapi that I create from scratch but im still having the same issue
r
Thanks @dleiva04
@KShivendu will have a look
d
Thank you @rp_st @KShivendu for the help
k
Still not able to replicate the issue. Everything is working fine with python3.8 for me. Can you give me dump of
pip freeze > requirements.txt
?
Ohh wait. I get the same errors as you if I remove
app.add_middleware(get_middleware())
.
However the control flow doesn't reach
response = await call_next(request)
of
fastapi_middleware.py
Let try this.
d
Also, im using conda to create the environment
r
hey @dleiva04 we are not able to replicate the issue with the file you sent either. Would it be possible for you to setup a dev env on gitpod with the issue replicated and share that link?
d
Yes! I will create one
r
thank you so much 🙂
d
Ok
I was trying something else
Because I was now sure that it was something with my env
So I change from anaconda3 to miniconda3
Now, its working
I also uninstall and delete everything related to .anaconda and .conda
So maybe just a FYI, maybe using anaconda is causing that error?
Now its working properly
That was the issue then, thank you @rp_st and @KShivendu for the help, i really appreciate it
k
great. iirc anaconda can have different version of libs compared to pypi. it's like a different ecosystem altogether. so probably some of the libs might be outdated. hence the error..
happy to hear that it finally worked. thanks a lot for your patience. feel free to reach out if there's anything else that we can help with. 😄
2 Views