solara
solara copied to clipboard
Cookies are set after on_kernel_start is triggered, which is not ideal.
See https://github.com/widgetti/solara/issues/773#issuecomment-2331062185 for the discussion.
I can imagine that we also need to think about how this would play with a possible reactive effect #474
Current best workaround for this:
@solara.lab.on_kernel_start
def init_auth():
# cookies are not available now
# but once the async task is running it is all set
# workaround for https://github.com/widgetti/solara/issues/774
init_auth_task()
@solara.lab.task(prefer_threaded=False)
async def init_auth_task():
print("cookies on kernel start", solara.lab.cookies.value)
try:
app_state.user.auth_token.value = solara.lab.cookies.value.get("authtoken", None)
except Exception as e:
print("Error loading auth token from cookie", e)
Not 100% if this is the right/best solution, I need to give this some thought. It might be the real solution.