Streamlit-Authenticator: Getting random_cookie_name error

Hi @mkhorasani thanks for this amazing package, I kindly request your assistance with an issue that’s surfaced with a Streamlit app we’ve recently deployed on Azure cloud. From yesterday, we’ve been encountering a peculiar ‘Random_cookie_name’ error that’s preventing some users from logging out. It’s interesting to note that it’s not a universal issue - some of our users from different geographical locations are able to logout without trouble. To assist you in troubleshooting, I’m attaching a screenshot along with a sample yml file and script. Your expertise and guidance on this matter would be greatly appreciated. image yml file

credentials:
  usernames:
    hk:
      email: hk@gmail.com
      name: hkhan
      password: "my hashed password" # 
##some other user names 
#file ends with 
cookie:
  expiry_days: 0
  key: "random_signature_key" # Must be a string
  name: "random_cookie_name" #we did not change it , kept it as random_cookie_name 
preauthorized:
  emails:
  - hk@gmail.com
```


our main file authentication code is 
```
with open('chatbot_users.yml') as file:  ##../
    config = yaml.load(file, Loader=SafeLoader)

authenticator = stauth.Authenticate(
    config['credentials'],
    config['cookie']['name'],
    config['cookie']['key'],
    config['cookie']['expiry_days'],
    config['preauthorized']
)
```

About this issue

  • Original URL
  • State: closed
  • Created 4 months ago
  • Comments: 25 (8 by maintainers)

Commits related to this issue

Most upvoted comments

Having the same issue. Solution I’m using:

class FixedAuthenticate(stauth.Authenticate): 
  def _implement_logout(self):
        # Clears cookie and session state variables associated with the logged in user.
        try:
            self.cookie_manager.delete(self.cookie_name)
        except Exception as e: 
            print(e)
        self.credentials['usernames'][st.session_state['username']]['logged_in'] = False
        st.session_state['logout'] = True
        st.session_state['name'] = None
        st.session_state['username'] = None
        st.session_state['authentication_status'] = None

authenticator = FixedAuthenticate(...) 

It’s a temporary fix that doesn’t address the underlying issue of the cookie getting lost in the first place, but it does let the logout complete even if the issue occurs.

Explanation: inherit the Authenticate class, change the loggout implementation to catch exception from deleting the cookie.

😭Hi @mkhorasani , may I ask when will the new version will be released?

Apologies for the delay, still working on it.

No need to apologies, you did a great work for us❤️! Just take your time!

Okay, by the looks of it, the reauthentication cookie has already been deleted. What I can do is that in a future release, when the library attempts to delete a cookie that has already been deleted, instead of throwing a fatal error I can throw a non-fatal error that allows the user to continue using the application while the error is logged on the console for the developer’s notice. I think this would be a reasonable fix for the time being.

@mkhorasani do let us know when you release the next version, that will help us

I’m going to release v0.3.2 in the coming days, with the new version of Extra-Streamlit-Components v0.1.70 (the library that manages the cookies), hopefully these problems should be resolved.

Collecting streamlit-authenticator

Downloading streamlit_authenticator-0.3.1-py3-none-any.whl (17 kB)

I have this issue consistently when hosting on Streamlit cloud, but it works fine when hosting locally. I’m not seeing the cookie getting written when hosting on Streamlit cloud for me. Same issue across browsers as well. Tried Chrome and Firefox.