Streamlit Authenticator: Logout - Are you sure message?

I am using “streamlit_authenticator” package to display login screen for my app. It’s a nice piece of work. Thank you Mohammad Khorasani!

I need a little control over my “logout” button. I want to ask the user “Are you sure you want to logout?” / “Are you sure to abandon your work?” etc.

How do I do this?

LATER
Ferdy gave a nice workaround. But as advised by Ferdy, I did raise an issue with the streamlit-authenticator package. You can find it here. Thank you @ferdy.
The solution given in that thread by the author of the package is the best solution for this.
The “logout” function takes “unrendered” as one of the values for the “location” parameter. When passed like that, it will perform the logout operation without rendering the button. So this allows us to render a button, ask for confirmation etc. and then call the actual logout() function with location parameter set to “unrendered” to perform the actual logout. That’s a neat design. Thanks to author of Streamlit-authenticator (Mr. Mohammad Khorasani)

2 Likes

This is not supported. However you can raise an issue in its repo asking this feature.

In the meantime you can create a custom logout system, that adds one layer of logout verification.

The logout buttton will only be shown if the user tick the checkbox.

code

if st.session_state["authentication_status"]:
    with st.container(border=True):
        st.subheader('Logout')
        st.checkbox('Verify logout', key='verify_logout')
        if st.session_state.verify_logout:
            authenticator.logout()
        
    st.write(f'Welcome *{st.session_state["name"]}*')
    st.title('Some content')
1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.