GauriSP10 / streamlit_login_auth_ui

It lets you connect your streamlit application to a pre-built and secure Login/ Sign-Up page.
MIT License
178 stars 59 forks source link

multipage APP #13

Open wangjiawen2013 opened 1 year ago

wangjiawen2013 commented 1 year ago

Hi, Streamlit now support multipage app (https://docs.streamlit.io/library/get-started/multipage-apps). Then how to use streamlit_login_auth_ui where there are many pages ?

fsmosca commented 1 year ago

Here is a sample scheme. Users can only log in/out from the main page. Store a login session state variable so that other pages has login info. They can use it to open its contents.

Sample layout.

main.py

import streamlit as st
from streamlit_login_auth_ui.widgets import __login__

if 'login' not in st.session_state:
    st.session_state.login = False

__login__obj = __login__(auth_token="courier_auth_token",
                    company_name="Shims",
                    width=200, height=250,
                    logout_button_name='Logout', hide_menu_bool=False,
                    hide_footer_bool=False,
                    lottie_url='https://assets2.lottiefiles.com/packages/lf20_jcikwtux.json')

st.session_state.login = __login__obj.build_login_ui()

if st.session_state.login:
   st.markdown("Welcome to Main page!")

pages/chatgpt.py

import streamlit as st

if 'login' not in st.session_state:
    st.session_state.login = False

if st.session_state.login:
    st.write('Welcome to ChatGPT')
else:
    st.write('Please login in the main page to see its contents.')
wangjiawen2013 commented 1 year ago

Thanks, it really helps a lot. In some cases, I want to forbid to create new accounts, could you add that function/option ?

fsmosca commented 1 year ago

I already have that feature on my branch. This is now offered as pull request.

wangjiawen2013 commented 1 year ago

Hi, In the following code: loginobj = login(auth_token="courier_auth_token", company_name="Shims", width=200, height=250, logout_button_name='Logout', hide_menu_bool=False, hide_footer_bool=False, lottie_url='https://assets2.lottiefiles.com/packages/lf20_jcikwtux.json') What's the function of [auto_token="courier_auth_token"] ? I changed the vaule to "abcdefg" and nothing happened to my streamlit APP. Besides, after I registratored a new account, I didn't received any email. But I investigated the source code and found that this login_auth_ui indeep has an function to send email. What's wrong ? and I don't understand the relationship between login_auth_ui and courier.

fsmosca commented 1 year ago

From the readme:

auth_token : The unique authorization token received from - https://www.courier.com/email-api/

wangjiawen2013 commented 1 year ago

I am a bit know what it is. Only a few people hear about courier in some countries and no one use it. So it didn't work for us.

wangjiawen2013 commented 1 year ago

Yes, we have never heard about courier before. I registered on https://www.courier.com/email-api/, now I often receive spam emails from courier. Could you tell us how to get authorization token from courier and how to use it ?