Logout button using streamlit-authenticator with multipages

Hi guys, I’ve created an app with streamlit-authenticator. It’s works well but the button to logout after login is just appearing in my Home.py (on sidebar), the same point where login lines was wrote. I would like to put this button in all pages.

For the pages, i’m using the structured folder pages, eg: pages/page_1.py pages/page_2.py, etc…

The app is not deployed yet.
My python is 3.10.11

Here the Home.py code:

import streamlit as st
import yaml
from yaml.loader import SafeLoader
import streamlit_authenticator as stauth

st.set_page_config(initial_sidebar_state="collapsed")

def main():
    st.title("Sistema de Controle de Atividades")

    with open('defs/config.yaml') as file:
        config = yaml.load(file, Loader=SafeLoader)

    authenticator = stauth.Authenticate(
        config['credentials'],
        config['cookie']['name'],
        config['cookie']['key'],
        config['cookie']['expiry_days'],
        config['preauthorized']
    )


    authentication_status = False

    if not authentication_status:
        tab_login, tab_register = st.tabs(["Login","Registrar"])
        with tab_login:
            if not authentication_status:
                name, authentication_status, username = authenticator.login('Login', 'main')

                #MyPass@01
                if authentication_status:
                    st.caption("Navegue no menu a esquerda para as opções do sistema")
                    authenticator.logout('Logout', 'sidebar', 'my_crazy_random_signature_key')
                    if username == 'admin':
                        print(None)
                    elif username == 'rbriggs':
                        print(None)
                elif authentication_status == False:
                    st.error('CNPJ/password incorreto.')
                elif authentication_status == None:
                    st.warning('Entre com seu CNPJ e senha.')
                        
                

    if not authentication_status:
        with tab_register:
            try:
                if not authentication_status:
                    if authenticator.register_user('Registre seu CNPJ como username!', preauthorization=False) :
                        with open('defs/config.yaml', 'w') as file:
                            yaml.dump(config, file, default_flow_style=False)

                        st.success('Usuário registrado!')
            except Exception as e:
                st.error(e)


if __name__=='__main__':
    main()

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