St.logout on Multipage Site

Currently on 1.44, locally hosted, and I recently experimented with a multipage site using st.navigation. I have created a simple account page with a logout button, but whenever I click it, it loads this “/auth/logout” but the logout doesn’t actually occur. I’m logging in using st.login connected to Microsoft SSO.

import streamlit as st

st.write(f"Hello, {st.experimental_user.name}!")

if st.button("Logout"):
    st.logout()
    ```

@Daniel_Turner try a st.rerun() after the logout to see the session information cleared in the re-rendered user page.

Thanks for the suggestion. Is this what you had in mind?

import streamlit as st

st.write(f"Hello, {st.experimental_user.name}!")

if st.button("Logout"):
    st.logout()
    st.rerun()

If so, I tested it, but when clicking the Logout button, i’m still redirected to http://localhost:8501/auth/logout with no logout occurring. The auth/logout page isn’t something that I setup. It seems to be a result of the st.logout() function, but I was thinking it should clear the experimental_user settings and redirect me to my homepage instead.

I ended up getting it fixed. It was just a very bizarre chain of events on my side that led to the error. But just in case someone else struggles through it, this is what happened.

I had already created my streamlit project and logged in using st.login(), but then I moved it over to a new virtual environment. Once I relaunched it, I was still logged in based off my previous login, so all seemed well. But then I finally stumbled upon the error when I went to login again in a different browser. I hadn’t installed Authlib in my new virtual environment, so that was preventing the logout from functioning correctly, but not returning an error. So in my case, I just needed to install Authlib in my environment. Sorry for the run around.

1 Like

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