Spaces:
Sleeping
Sleeping
working user auth
Browse files- app.py +26 -20
- requirements.txt +2 -1
app.py
CHANGED
@@ -1,27 +1,33 @@
|
|
1 |
import streamlit as st
|
2 |
import uuid
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
|
4 |
def get_user_id():
|
5 |
-
if
|
6 |
-
#
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
window.parent.postMessage(userId, "*");
|
16 |
-
</script>
|
17 |
-
""",
|
18 |
-
height=0,
|
19 |
-
)
|
20 |
|
21 |
-
|
22 |
-
|
23 |
|
24 |
-
|
|
|
25 |
|
26 |
-
|
27 |
-
|
|
|
1 |
import streamlit as st
|
2 |
import uuid
|
3 |
+
from streamlit_cookies_manager import CookieManager
|
4 |
+
|
5 |
+
# Initialize the cookie manager without encryption
|
6 |
+
cookies = CookieManager(
|
7 |
+
prefix="my_app_" # You can use any prefix
|
8 |
+
)
|
9 |
+
|
10 |
+
# Ensure the cookies are ready
|
11 |
+
if not cookies.ready():
|
12 |
+
st.stop()
|
13 |
|
14 |
def get_user_id():
|
15 |
+
if 'user_id' not in cookies:
|
16 |
+
# Generate a new UUID
|
17 |
+
user_id = str(uuid.uuid4())
|
18 |
+
# Store it in cookies
|
19 |
+
cookies['user_id'] = user_id
|
20 |
+
cookies.save() # Save the cookies
|
21 |
+
else:
|
22 |
+
# Retrieve the user_id from cookies
|
23 |
+
user_id = cookies['user_id']
|
24 |
+
return user_id
|
|
|
|
|
|
|
|
|
|
|
25 |
|
26 |
+
def main():
|
27 |
+
st.title("Unique User ID with Persistent UUID")
|
28 |
|
29 |
+
user_id = get_user_id()
|
30 |
+
st.write(f"Your user ID is: `{user_id}`")
|
31 |
|
32 |
+
if __name__ == '__main__':
|
33 |
+
main()
|
requirements.txt
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
paho-mqtt==2.1.0
|
2 |
pillow==10.4.0
|
3 |
setuptools==75.1.0
|
4 |
-
wheel==0.44.0
|
|
|
|
1 |
paho-mqtt==2.1.0
|
2 |
pillow==10.4.0
|
3 |
setuptools==75.1.0
|
4 |
+
wheel==0.44.0
|
5 |
+
streamlit-cookies-manager==0.2.0
|