How to use mutipages and authencation together

 i  have created a multipage app ,which have three pages. the side menu list name is :defalut,second,first  .
 and i also created a login page  with the streamlit-login-auth-ui package.   i make an authentication for user in my “main page”  .
   the login page appear and protect only on the “default page”, other pages can access on the sidebar without having to login.
    Please help! Thank you…
    others.i use the streamlit-authentication package ,it is the same result.
2 Likes

Hi @hillstone,

Thank you for sharing your question with the community!

Your post is missing a code snippet and a link to your app’s GitHub repo. Please check out our guidelines on how to post an effective question here and update your post to help the community answer your question.

1.the code of the login.py is as follows

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

with open('./db/config.yaml',encoding='utf-8') 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']
)
name, authentication_status, username = authenticator.login('Login', 'main')
if authentication_status:
    with st.sidebar.container():
        cols1,cols2 = st.columns(2)
        cols1.write('欢迎 *%s*' % (name))
        with cols2.container():
            authenticator.logout('Logout', 'sidebar', key='unique_key')
    main_app.main()
elif authentication_status is False:
    st.error('Username/password is incorrect')
elif authentication_status is None:
    st.warning('Please enter your username and password')

2. the code of main_app.py is as follow:

import streamlit as st
from st_pages import Page, Section,show_pages, add_page_title
def main():
    show_pages(
        [
            Page("main_app.py",name="主页",icon="🏠"),
            Section(name="表格相关处理技术",icon="🏠"),
            Page("menuPages/table_linked.py", "主从表格",icon="💪"),
            Page("menuPages/second.py", "样例2",icon="💪"),
            Section(name="项目相关",icon="🏠"),
            Page("menuPages/xm.py", "项目",icon="💪"),
            Page("menuPages/tax.py", "税率",icon="💪"),
            # in_section=False用明确申明,该页不属于上面的菜单section子项目
            Page("menuPages/test.py",name="最后页面",icon="🏠",in_section=False),
        ]
    )    
if __name__ == '__main__':
    main()
    pass
2 Likes

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