Open elblogbruno opened 4 months ago
This is likely more related to how FastAPI handles requests than the library itself. You should use some sort of persistent storage setup with FastAPI as sessions aren't shared between requests.
Got it thanks! I will look into the safest way of doing it!
I was having a kinda of a similar issue where I only send the access_token to the backend and I would just have RLS problems when communicating with the supabase db.
Because the only way to set the session in the backend is by using the set_session
function where you have to pass both the access_token
and refresh_token
which didn't make sense for my to pass the refresh token from my frontend to my backend, and I was kinda stuck because the get_session
function doesn't take any params and we just can't get it.
after lot's of searching a solution that helped my was the following
client = await create_async_client(
settings.SUPABASE_PROJECT_URL,
settings.SUPABASE_API_KEY,
options=ClientOptions(headers={"Authorization": f"Bearer {access_token}"}),
)
which is basically when creating the client you have to pass the access_token like the above example, it would help with communicating with the supabase api's. But still even with that the get_session
still has the same problem.
idk if that helps
Hi, Many thanks for answering. So you create a new client for every endpoint on every request if I understand correctly? Finally I manage myself to append access token directly to storage object in python to get RLS and authentication working with storage module:
supa: Client = create_client(url, key)
supa.storage.session.headers["Authorization"] = f"Bearer {access_token}"
image = supa.storage.from_("test").create_signed_url(key, expires_in=3600)
Thanks for your answer Bruno
Bug report
Describe the bug
I am using supabase-py with fastapi.
I made a login endpoint that uses sign_in_with_password():
It returns access_token and refresh_token that then I save on my client. My client does requests with the access_token and I use an AuthBearer on fastapi to validate the token and get current user on every endpoint I have:
When using storage api and being logged in, session is None so consequent storage requests give errors.
There are files in there.
I made a sample file to test:
and this gives correct info!
Maybe I am doing something wrong?
Many thanks Bruno
To Reproduce
Steps to reproduce the behavior, please provide code snippets or a repository:
Expected behavior
supabase-py should maintain the session after authentication, allowing storage API calls to succeed as they do in the standalone script.
Screenshots
If applicable, add screenshots to help explain your problem.
System information
Additional context
Add any other context about the problem here.