mkhorasani/Streamlit-Authenticator

Auto login after registration

federico-cau-linkalab opened this issue · 3 comments

Hi, great job with this component, it is really useful.

I was trying to do a login or register and I thought it would be useful to be able to have automatic login after a registration done with register_user(), maybe with a boolean parameter, e.g. login=True. This would avoid trying to find a way to do a page reset, and it would be more convenient for users who register not to have to log in right afterwards.

This is the code I am using

if not st.session_state['authentication_status']:
    tab1, tab2 = st.tabs(["Login", "Register"])
    with tab1:
        authenticator.login(location='main')
    with tab2:
        email_of_registered_user, username_of_registered_user, name_of_registered_user = authenticator.register_user(preauthorization=False)
        if email_of_registered_user:
            st.success('User registered successfully')
            with open('./config.yaml', 'w') as file:
                yaml.dump(config, file, default_flow_style=False)

Excellent idea, I will look into it for a future release.

So, as of today, how is it possible to do an auto-login? Do we need to directly invoke the authentication_controller.login inside the authenticator object?

So, as of today, how is it possible to do an auto-login? Do we need to directly invoke the authentication_controller.login inside the authenticator object?

Hi @egeres, this is something that is not implemented natively yet. But if you wish to do it, I recommend that you try to manually write the authentication cookie after registration and then execute a st.rerun to log the user in. For more information on writing cookies, please take a look at the cookie model.