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/”)” 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


if st.button("Log out"):
    st.session_state["logged_in"] = False
    st.success("Logged out!")

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

For me the code at streamlit 1.31.0 GitHub - blackary/streamlit-login does not work
When ‘run’ the server it already starts with all the pages listed in the sidebar

after login, it shows the labelled version below as

where Info = Landing Page
Backtest = Backtest results
and Liverun = Live run results
the code is more or less a copy paste of the code of github code

finally figured out
…the trick is config.toml entry which hides the sidebar

showSidebarNavigation = false
1 Like