Hide all pages before logged in and after logged in don't show login page

I want to run below code for logging page but showing error : ImportError: cannot import name ‘_on_pages_changed’ from ‘streamlit.source_util’ (C:\Users\Computer\Envs\env\lib\site-packages\streamlit\source_util.py).I have installed st-pages==0.4.1 and streamlit version 1.52.

Here i am mainly trying to hide all the pages before logged in,only login page will visible to user and after logged in other pages will appear but not login page.After clicking the logout button again the above process repeats.

import streamlit as st

from st_pages import show_pages, Page, hide_pages

import sqlite3

import time

# — Configuration for st-pages —

# Define all pages statically once at the top of your main script

# The ‘After Login’ page should be in a ‘pages’ subdirectory in your project structure.

show_pages(

\[

    Page("streamlit_app.py", "Home", icon="🏠"),

    Page("pages/secret_page.py", "After Login", icon="🔒"),

\]

)

hide_pages([“After Login”])

# — Database Setup (Ensure your DB and table exist) —

DB_FILE = “login.db”

# — Database Functions —

def authenticate_user(username, password):

"""

Checks the database for a matching username and password.

Returns True if valid, False otherwise.

"""

connection = sqlite3.connect(DB_FILE)

cursor = connection.cursor()



\# Use parameterized queries to prevent SQL injection

query = "SELECT \* FROM users WHERE username = ? AND password = ?"

cursor.execute(query, (username, password))



\# Fetch one matching record (if any)

user_record = cursor.fetchone()



connection.close()



\# If user_record is not None, a match was found

return user_record is not None

# — Streamlit UI —

col1, col2, col3 = st.columns([1, 2, 1])

with col2:

st.title("🔐 User Login")

st.subheader("Login to Your Account")



\# Use session state to manage login status across reruns

if 'logged_in' not in st.session_state:

    st.session_state\['logged_in'\] = False



\# Check login status and dynamically show/hide pages

if st.session_state\['logged_in'\]:

    \# If logged in, show the secret page in the sidebar navigation

    show_pages(

        \[

            Page("streamlit_app.py", "Home", icon="🏠"),

            Page("pages/secret_page.py", "After Login", icon="🔒"), # Make sure it's visible now

        \]

    )

    \# Display success message in the main container

    st.success(f"You are currently logged in as {st.session_state\['username'\]}.")

    

    \# We don't use st.switch_page immediately here in the main script; 

    \# the user should use the new sidebar navigation to move to 'After Login'.

    

    if st.button("Logout"):

        st.session_state\['logged_in'\] = False

        st.session_state.pop('username', None)

        \# Re-hide the pages upon logout

        hide_pages(\["After Login"\])

        st.info("Logged out successfully.")

        st.rerun() # Rerun to update the UI and sidebar

        



else:

    \# If not logged in, show the login form and ensure secret pages are hidden

    hide_pages(\["After Login"\]) 

    

    with st.form("login_form"):

        username_input = st.text_input("Username", placeholder="Enter your username (e.g., testuser)")

        password_input = st.text_input("Password", placeholder="Enter your password (e.g., password123)", type="password")



        col11, col12 = st.columns(\[1, 3\])

        login_button = col11.form_submit_button("Login")

        

        if login_button:

            if not username_input or not password_input:

                st.warning("⚠️ Please fill in both username and password.")

            else:

                if authenticate_user(username_input, password_input):

                    st.session_state\['logged_in'\] = True

                    st.session_state\['username'\] = username_input

                    st.success(f"✅ Welcome, {username_input}! Updating navigation...")

                    time.sleep(1) # Small delay for UX

                    st.rerun() # Rerun the script to update the UI and \*reveal\* the sidebar pages

                else:

                    st.error("❌ Invalid username or password.")