Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,5 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import requests
|
| 3 |
-
import os
|
| 4 |
|
| 5 |
# Firebase Auth REST API to login
|
| 6 |
def firebase_login(email, password):
|
|
@@ -21,42 +20,37 @@ def firebase_login(email, password):
|
|
| 21 |
|
| 22 |
def main():
|
| 23 |
st.set_page_config(page_title="Login", layout="centered")
|
| 24 |
-
|
| 25 |
-
# Header
|
| 26 |
-
st.title("Login")
|
| 27 |
-
st.markdown("---")
|
| 28 |
|
| 29 |
# Check login state
|
| 30 |
if "logged_in" not in st.session_state:
|
| 31 |
st.session_state.logged_in = False
|
| 32 |
|
| 33 |
-
#
|
| 34 |
if st.session_state.logged_in:
|
| 35 |
-
st.
|
| 36 |
st.write("Redirecting to your dashboard...")
|
| 37 |
-
|
|
|
|
|
|
|
|
|
|
| 38 |
|
| 39 |
# Login form if not logged in
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
# Alternatively, you can manually run app2.py if necessary
|
| 57 |
-
os.system('streamlit run app2.py')
|
| 58 |
-
else:
|
| 59 |
-
st.error("Login failed. Please check your credentials.")
|
| 60 |
|
| 61 |
if __name__ == "__main__":
|
| 62 |
main()
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import requests
|
|
|
|
| 3 |
|
| 4 |
# Firebase Auth REST API to login
|
| 5 |
def firebase_login(email, password):
|
|
|
|
| 20 |
|
| 21 |
def main():
|
| 22 |
st.set_page_config(page_title="Login", layout="centered")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
# Check login state
|
| 25 |
if "logged_in" not in st.session_state:
|
| 26 |
st.session_state.logged_in = False
|
| 27 |
|
| 28 |
+
# Check if already logged in
|
| 29 |
if st.session_state.logged_in:
|
| 30 |
+
st.write("You are already logged in.")
|
| 31 |
st.write("Redirecting to your dashboard...")
|
| 32 |
+
|
| 33 |
+
# Update URL with the page parameter to redirect to app2.py
|
| 34 |
+
st.experimental_set_query_params(page="app2")
|
| 35 |
+
return
|
| 36 |
|
| 37 |
# Login form if not logged in
|
| 38 |
+
email = st.text_input("Email")
|
| 39 |
+
password = st.text_input("Password", type="password")
|
| 40 |
+
|
| 41 |
+
if st.button("Login"):
|
| 42 |
+
user_id, id_token = firebase_login(email, password)
|
| 43 |
+
if user_id:
|
| 44 |
+
st.session_state.logged_in = True
|
| 45 |
+
st.session_state.email = email
|
| 46 |
+
st.session_state.user_id = user_id
|
| 47 |
+
|
| 48 |
+
# Update the URL with the page query parameter
|
| 49 |
+
st.experimental_set_query_params(page="app2")
|
| 50 |
+
|
| 51 |
+
st.success("Login successful! Redirecting to your dashboard...")
|
| 52 |
+
else:
|
| 53 |
+
st.error("Login failed. Please check your credentials.")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
|
| 55 |
if __name__ == "__main__":
|
| 56 |
main()
|