Skip to content

Flicker/Double Load of Login Screen with streamlit-authenticator on App Startup #263

@ShikharUser

Description

@ShikharUser

I'm encountering a flicker/double load issue on startup when using the streamlit-authenticator-mongo package for authentication in my Streamlit app. The problem is that when a user first visits the app, the session state for authentication (st.session_state["authentication_status"]) is initially None, which triggers the login screen. Shortly after, the authentication process sets this value to True (for authenticated users), and the app re-runs, switching to the main screen. This results in the following sequence:

  1. Initial Run:

st.session_state["authentication_status"] is None.
The code treats this as an unauthenticated state and displays the login screen.

  1. Subsequent Run:
    The authentication library updates st.session_state["authentication_status"] to True.
    The app re-runs and displays the main UI.

This causes a brief but noticeable flicker where the login screen appears before the main content is rendered, even if the user is already authenticated.

    menu = ["Login", "Register"]
    choice = st.sidebar.selectbox("Menu", menu)
    if choice == "Login":
        authenticator.login('Login', 'main')
    elif choice == "Register":
        # Registration form logic...```

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions