SiddhantSadangi/st_login_form

st_login_form with multiple pages switch_page doesn't open pages

Closed this issue · 8 comments

First of all, thank you for this wonderful streamlit component. I would like to use your st_login_form component to my app. When the user is logged in, it should open the app which has multiple pages using st.switch_page. Unfortunately, it keeps cycling between the logging page and opening page (but it doesn't show it). I'm not sure how I can create a reproducible example for you since I'm using a Supabase. Here I can show you two screenshots to show you how the app keeps cycling between these pages (I can't use the app because it switches between these pages):

image

And this:

image

I hope this makes it a bit more clear. It feels like there is a bug when using st_login_form in combination with st.switch_page. Thanks in advance!


I'm using streamlit 1.32.0

Hey @QuintenSand ,
Thanks for letting me know about this. I'll try to have a look over the weekend

Hey @QuintenSand , Thanks for letting me know about this. I'll try to have a look over the weekend

Thank you for your response @SiddhantSadangi , I'm really looking forward to your solution! Thanks in advance!

Hey @QuintenSand ,

I am not able to reproduce this issue.

Here is my test setup:

python 3.8.10
streamlit 1.32.0

app.py

import streamlit as st
from st_login_form import login_form

client = login_form()

if st.session_state["authenticated"]:
    if st.button("Page 1"):
        st.switch_page("pages/page_1.py")
    if st.button("Page 2"):
        st.switch_page("pages/page_2.py")

page_1.py

import streamlit as st

st.write("page 1")

if st.button("Home"):
    st.switch_page("app.py")
if st.button("Page 2"):
    st.switch_page("pages/page_2.py")

page_2.py

import streamlit as st

st.write("page 2")

if st.button("Home"):
    st.switch_page("app.py")
if st.button("Page 1"):
    st.switch_page("pages/page_1.py")

As you can see in the below screen recording, I am able to switch between pages seamlessly after authentication with login_form()

Untitled.video.-.Made.with.Clipchamp.mp4

It would help if you could share a minimal code snippet of how you are using st_login_form and st.switch_page(), along with a screen recording that captures this issue.

Hi @SiddhantSadangi , Thank you for your time. I took me a bit longer than expected but I hope that this is a minimal reproducible example. First I would like to show the screen record of what is happening here:

Streamlit.login.video.mov

As you can see the login page keeps refreshing and switching between pages. So I'm not able to go to the two pages I created.

I created a private repo (Please keep in mind that the project is in working progress). The code is on the develop branch. Also I use a supabase to let the user create an account. I just sended you an invite to my repo. Thanks in advance for your help!

Thanks for sharing the repo!

The issue is here: https://github.com/QuintenSand/Mario-Kart-track-recorder/blob/9921914ba49ed4bd0cadee900cd993db7ac15610/src/functions.py#L37

When you call this function in the submit page, it switches to the main app page, leading to an infinite loop scenario. Commenting out this elif block fixes the issue.

Closing this issue as this has nothing to do with st_login_form(), but please feel free to comment if you need any further support :)

And thanks for using st_login_form() 🤝
If you find this library useful, I'd love to receive a star and share on socials 🤗

Commenting the elif block was the fix. Thank you very much for your support! I love your st_login_form function. Thanks again!

This is an awesome library, however can a user not just click on the other pages in the sidebar without authenticating? This defeats the purpose of the Authentication / Login page?

@aYoHoldings - st_login_form uses the authenticated session state to record authentication status.
@QuintenSand is using logged_in to check if the user has logged in, and this is leading to the infinite loop.

Replacing logged_in with authenticated here and here fixes the issue, and prevents users from accessing the pages unless logged in.

You can also conditionally display the other pages by building a custom navigation menu.