When I first run the app, the login form is duplicated on submit. On later attempts, it displays correctly. How can I fix this?
def show_login_form():
st.title("Authorization")
with st.form("login_form"):
username = st.text_input("Login", placeholder="Enter your login")
password = st.text_input("Password", type="password", placeholder="Enter your password")
remember_me = st.checkbox("Remember me", value=False)
submitted = st.form_submit_button("Enter")
if submitted:
if not username or not password:
st.error("Enter login and password")
return False
return login_to_api(username, password, remember_me)
return False
app.py:
def main():
if 'authenticated' not in st.session_state:
st.session_state.authenticated = False
if not st.session_state.authenticated:
if restore_session_from_cookies():
st.success(f"Welcome, {st.session_state.username}!")
else:
if show_login_form():
st.rerun()
st.stop()
pg = st.navigation([
st.Page("pages/main.py", title="Main", icon="🏠"),
st.Page("pages/employee.py", title="Employees", icon="👤")
])
pg.run()
if __name__ == "__main__":
main()
