import streamlit as st import firebase_admin from firebase_admin import credentials, auth from firebase_admin import initialize_app def initialize_firebase(): if not firebase_admin._apps: cred = credentials.Certificate(st.secrets["firebase"]) initialize_app(cred) def check_authentication(): initialize_firebase() if 'user_authenticated' not in st.session_state: st.session_state.user_authenticated = False if not st.session_state.user_authenticated: col1, col2 = st.columns(2) with col1: email = st.text_input("Email") with col2: password = st.text_input("Password", type="password") col1, col2 = st.columns(2) with col1: if st.button("Login"): try: user = auth.get_user_by_email(email) st.session_state.user_authenticated = True st.experimental_rerun() except: st.error("Invalid credentials") with col2: if st.button("Sign Up"): try: user = auth.create_user( email=email, password=password ) st.success("Account created successfully!") except: st.error("Could not create account") return False return True