From 7443aebd9ee3d7dbe64a9ea84a2845530653577c Mon Sep 17 00:00:00 2001 From: Josh XT Date: Wed, 12 Jun 2024 23:16:38 -0400 Subject: [PATCH] dont request code if empty --- components/Auth.py | 53 +++++++++++++++++++++++----------------------- 1 file changed, 27 insertions(+), 26 deletions(-) diff --git a/components/Auth.py b/components/Auth.py index 6bcc9bc3..447ec4ca 100644 --- a/components/Auth.py +++ b/components/Auth.py @@ -50,37 +50,38 @@ def google_sso_button(): ) st.stop() if "code" in st.query_params: - if st.query_params["code"] != "": + if st.query_params["code"] != "" and st.query_params["code"] is not None: if isinstance(st.query_params["code"], list): code = str(st.query_params["code"][0]) else: code = str(st.query_params["code"]) - response = requests.post( - f"{auth_uri}/v1/oauth2/google", - json={ - "code": code, - "referrer": magic_link_uri, - }, - ) - res = response.json() - if "detail" in res: - details = str(res["detail"]) - if details.startswith("http"): - token = details.split("token=")[1] - set_cookie("token", token, 1, "google_sso_token") - # Redirect to the login link - st.markdown( - f'', - unsafe_allow_html=True, - ) - time.sleep(0.5) - st.stop() + if code != "": + response = requests.post( + f"{auth_uri}/v1/oauth2/google", + json={ + "code": code, + "referrer": magic_link_uri, + }, + ) + res = response.json() + if "detail" in res: + details = str(res["detail"]) + if details.startswith("http"): + token = details.split("token=")[1] + set_cookie("token", token, 1, "google_sso_token") + # Redirect to the login link + st.markdown( + f'', + unsafe_allow_html=True, + ) + time.sleep(0.5) + st.stop() + else: + st.error(details) + logging.error(f"Error with Google SSO: {details}") else: - st.error(details) - logging.error(f"Error with Google SSO: {details}") - else: - st.error(response.text) - logging.error(f"Error with Google SSO: {response.text}") + st.error(response.text) + logging.error(f"Error with Google SSO: {response.text}") def get_user():