Spaces:
Sleeping
Sleeping
File size: 1,133 Bytes
2cc5127 |
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 35 |
import chainlit as cl
import base64
import json
@cl.header_auth_callback
def header_auth_callback(headers: dict) -> Optional[cl.User]:
print("\n\n\nI am here\n\n\n")
# try: # TODO: Add try-except block after testing
# TODO: Implement to get the user information from the headers (not the cookie)
cookie = headers.get("cookie") # gets back a str
# Create a dictionary from the pairs
cookie_dict = {}
for pair in cookie.split("; "):
key, value = pair.split("=", 1)
# Strip surrounding quotes if present
cookie_dict[key] = value.strip('"')
decoded_user_info = base64.b64decode(
cookie_dict.get("X-User-Info", "")
).decode()
decoded_user_info = json.loads(decoded_user_info)
return cl.User(
identifier=decoded_user_info["email"],
metadata={
"name": decoded_user_info["name"],
"avatar": decoded_user_info["profile_image"],
},
)
@cl.on_chat_start
async def start():
await cl.Message(content = "HELLO").send()
|