Akshayram1 commited on
Commit
150fbaa
·
verified ·
1 Parent(s): 8ad1af4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -28
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
- # If already logged in, redirect to the main app (app2.py)
34
  if st.session_state.logged_in:
35
- st.success("You are already logged in.")
36
  st.write("Redirecting to your dashboard...")
37
- st.experimental_set_query_params(page="app2") # Set URL query to indicate page switch
 
 
 
38
 
39
  # Login form if not logged in
40
- else:
41
- email = st.text_input("Email")
42
- password = st.text_input("Password", type="password")
43
-
44
- if st.button("Login"):
45
- user_id, id_token = firebase_login(email, password)
46
- if user_id:
47
- st.session_state.logged_in = True
48
- st.session_state.email = email
49
- st.session_state.user_id = user_id
50
-
51
- # Store session state and redirect to app2.py
52
- st.success("Successfully logged in!")
53
- st.write("Redirecting to your dashboard...")
54
- st.experimental_set_query_params(page="app2") # Set URL query to indicate page switch
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()