Hi I am wondering how to properly cache the Supabase’s access and refresh token. I understand that I can cache the client (see code below). In my current application though, with every rerun I am singing in again (i.e. running supabase.auth.sign_in_with_password
). Is there a better way to do this?
import streamlit as st
from supabase import Client, create_client
@st.cache_resource
def init_supabase_connection() -> Client:
url = st.secrets["SUPABASE_URL"]
key = st.secrets["SUPABASE_KEY"]
client = create_client(url, key)
return client
supabase = init_supabase_connection()
user_data = supabase.auth.sign_in_with_password(
{
"email": st.secrets["SUPABASE_EMAIL"],
"password": st.secrets["SUPABASE_PASSWORD"],
}
)
sb_user_id = user_data.user.id
supabase.auth.set_session(
access_token=user_data.session.access_token,
refresh_token=user_data.session.refresh_token,
)