cobot280pi / app.py
gursi26's picture
working user auth
0078aeb
raw
history blame
801 Bytes
import streamlit as st
import uuid
from streamlit_cookies_manager import CookieManager
# Initialize the cookie manager without encryption
cookies = CookieManager(
prefix="my_app_" # You can use any prefix
)
# Ensure the cookies are ready
if not cookies.ready():
st.stop()
def get_user_id():
if 'user_id' not in cookies:
# Generate a new UUID
user_id = str(uuid.uuid4())
# Store it in cookies
cookies['user_id'] = user_id
cookies.save() # Save the cookies
else:
# Retrieve the user_id from cookies
user_id = cookies['user_id']
return user_id
def main():
st.title("Unique User ID with Persistent UUID")
user_id = get_user_id()
st.write(f"Your user ID is: `{user_id}`")
if __name__ == '__main__':
main()