Issue creating seperate logins for admin and general user (page keeps loading)

Hello everyone ,
I have tried to created a web app it needs to have different login approach for admin and generic users. I have tried Integrating, debugging and what not to the code but it keeps loading when I try to use register or login. I have included cookies, session timeouts I am quite new so I have used the Ai assistant well , I cleared my last problem of session timeout thankfully. I can’t understand the actual problem why the application is stuck on loading but it stores the email credentials on my FB database ,I don’t know how to proceed further. I will provide the code please don’t block my query :

CODE:

Authentication functions for login, registration, and password reset

def login_user(email, password):
try:
user = auth_client.sign_in_with_email_and_password(email, password)
return user
except:
return None

def register_user(email, password):
try:
auth_client.create_user_with_email_and_password(email, password)
return True
except:
return False

def reset_password(email):
try:
auth_client.send_password_reset_email(email)
return True
except:
return False

def main():
st.title(‘Firebase Authentication with Streamlit’)

# Initialize session states
if "logged_in" not in st.session_state:
    st.session_state["logged_in"] = False
if "register" not in st.session_state:
    st.session_state["register"] = False
if "forgot_password" not in st.session_state:
    st.session_state["forgot_password"] = False  # To control the password reset visibility

if st.session_state["logged_in"]:
    st.write("You have logged in.")
    if st.button("Logout"):
        st.session_state["logged_in"] = False
        st.rerun()

elif st.session_state["register"]:
    st.subheader("Register a New Account")
    email = st.text_input("Enter your email")
    password = st.text_input("Enter your password", type="password")
    confirm_password = st.text_input("Confirm your password", type="password")

    if st.button("Register"):
        if password == confirm_password:
            if register_user(email, password):
                st.success("Registration successful! You can now log in.")
                st.session_state["register"] = False
                st.rerun()
            else:
                st.error("Registration failed. Try again.")
        else:
            st.error("Passwords do not match. Please try again.")

    if st.button("Back to Login"):
        st.session_state["register"] = False
        st.rerun()

else:
    st.subheader("Login")
    email = st.text_input("Enter your email")
    password = st.text_input("Enter your password", type="password")

    if st.button("Login"):
        user = login_user(email, password)
        if user:
            st.session_state["logged_in"] = True
            st.rerun()
        else:
            st.error("Invalid email or password")

    if st.button("Sign Up"):
        st.session_state["register"] = True
        st.rerun()

    if st.button("Forgot Password"):
        st.session_state["forgot_password"] = not st.session_state["forgot_password"]

    if st.session_state["forgot_password"]:
        st.subheader("Forgot Password")
        reset_email = st.text_input("Enter your email for password reset")
        if st.button("Send Password Reset Email"):
            if reset_email:
                if reset_password(reset_email):
                    st.success("Password reset email sent! Check your inbox.")
                else:
                    st.error("Failed to send password reset email. Please try again.")
            else:
                st.error("Please enter a valid email address.")

if name == ‘main’:
main()

To use ai, try to use it progressively. Implement feature 1, test feature 1, if ok save it. Implement feature 2, test feature 2 and so on. This way, you will be able to identify the issue immediately.

1 Like

I have tried using it and providing it code seperately as well I just don’t know what is wrong here and why it keeps loading instead of going to the login step

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