Redirecting login page to home page

hi guys im trying to redirect the login page to the home page after a successful login, but im having trouble figuring it out. i’ve reviewed the streamlit documentation on multipage apps but it doesn’t provide the solution im looking for. rn im using “st.switch_page(“pages/home.py”)” after a succesful login but this makes the home page also appear on the sidebar before even logging in. idk if theres a way to hide it in the sidebar or another solution?? ty in advance

Could you post a sample minimal code that we can test?

You might be interested in this post, which shows how you can hide pages until logging in using the st_pages package.

The one piece that is different in your request is that you want to hide the home page after you log in, which you can do by switching hide_pages([]) to hide_pages(["login"]) (or whatever your log in page is called that you want to hide).

Note that this hiding simply happens by CSS, and needs to be done on every page of your app to make it work. For example, you might put this in every page in your app:

(The sleep isn’t necessary, just makes it more obvious what’s happening before the page switch)

import streamlit as st
from time import sleep
from st_pages import hide_pages

hide_pages(["login"])

if st.button("Log out"):
    st.session_state["logged_in"] = False
    st.success("Logged out!")
    sleep(0.5)
    st.switch_page("login.py")

Note also that st.switch_page is part of the official streamlit package, and works slightly differently from hide_pages, which comes from the unofficial st_pages package.

1 Like

Here’s a new improved version of this, which uses the new features of streamlit 1.31.0 GitHub - blackary/streamlit-login

Here’s an example app in action https://app-app.streamlit.app/