solara icon indicating copy to clipboard operation
solara copied to clipboard

Cookies are set after on_kernel_start is triggered, which is not ideal.

Open maartenbreddels opened this issue 1 year ago • 1 comments

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

maartenbreddels avatar Sep 05 '24 09:09 maartenbreddels

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.

maartenbreddels avatar Sep 11 '24 08:09 maartenbreddels