File size: 801 Bytes
be196d0
68cb778
0078aeb
 
 
 
 
 
 
 
 
 
68cb778
 
0078aeb
 
 
 
 
 
 
 
 
 
46f7fb9
0078aeb
 
68cb778
0078aeb
 
46f7fb9
0078aeb
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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()