diff --git a/backend/user_management.py b/backend/user_management.py index 7ccb88b..ca80c1e 100644 --- a/backend/user_management.py +++ b/backend/user_management.py @@ -67,6 +67,6 @@ def create_access_token(*, data: dict, expires_delta: Optional[timedelta] = None if expires_delta: expire = datetime.utcnow() + expires_delta else: - expire = datetime.utcnow() + timedelta(minutes=15) + expire = datetime.utcnow() + timedelta(minutes=60) to_encode.update({"exp": expire}) return jwt.encode(to_encode, SECRET_KEY, algorithm=ALGORITHM) diff --git a/frontend/app.py b/frontend/app.py index 7541fa3..e832124 100644 --- a/frontend/app.py +++ b/frontend/app.py @@ -14,6 +14,9 @@ assets = Path(__file__).parent / "assets" +st.session_state["login_status_message"] = "" if "login_status_message" not in st.session_state else st.session_state["login_status_message"] +st.session_state["login_status_level"] = "info" if "login_status_level" not in st.session_state else st.session_state["login_status_level"] + if __name__ == "__main__": st.set_page_config( diff --git a/frontend/lib/auth.py b/frontend/lib/auth.py index 2dccb48..b170398 100644 --- a/frontend/lib/auth.py +++ b/frontend/lib/auth.py @@ -1,4 +1,5 @@ import os +from time import sleep from typing import Optional from urllib.parse import urljoin @@ -9,7 +10,6 @@ FASTAPI_URL = os.getenv("FASTAPI_URL", "http://localhost:8000/") - def auth() -> Optional[str]: tab = stx.tab_bar( data=[ @@ -31,6 +31,8 @@ def login_form(): with st.form("Login"): username = st.text_input("Username", key="username") password = st.text_input("Password", type="password") + if st.session_state["login_status_message"]: + getattr(st, st.session_state["login_status_level"])(st.session_state["login_status_message"]) submit = st.form_submit_button("Log in") if submit: @@ -40,7 +42,8 @@ def login_form(): session = create_session() session = authenticate_session(session, token) else: - st.error("Failed authentication") + st.session_state["login_status_level"] = "error" + st.session_state["login_status_message"] = "Username/password combination not found" st.session_state["session"] = session st.session_state["email"] = username st.rerun() @@ -50,6 +53,8 @@ def signup_form(): with st.form("Signup"): username = st.text_input("Username", key="username") password = st.text_input("Password", type="password") + if st.session_state["login_status_message"]: + getattr(st, st.session_state["login_status_level"])(st.session_state["login_status_message"]) submit = st.form_submit_button("Sign up") if submit: @@ -59,8 +64,14 @@ def signup_form(): token = get_token(username, password) session = create_session() auth_session = authenticate_session(session, token) + st.session_state["login_status_level"] = "success" + st.session_state["login_status_message"] = "Success! Account created." + if st.session_state["login_status_message"]: + getattr(st, st.session_state["login_status_level"])(st.session_state["login_status_message"]) + sleep(1.5) else: - st.error("Failed signing up") + st.session_state["login_status_level"] = "error" + st.session_state["login_status_message"] = "Failed signing up" st.session_state["session"] = auth_session st.session_state["email"] = username st.rerun() diff --git a/frontend/lib/backend.py b/frontend/lib/backend.py index 2e4b063..1aea480 100644 --- a/frontend/lib/backend.py +++ b/frontend/lib/backend.py @@ -8,6 +8,8 @@ def query(verb: str, url: str, **kwargs): if response.status_code == 401: st.session_state["session"] = None st.session_state["email"] = None + st.session_state["login_status_level"] = "error" + st.session_state["login_status_message"] = "Session expired. Please log in again." st.rerun() return response