TEST_TUTOR / main.py
XThomasBU's picture
Create main.py
2cc5127 verified
raw
history blame
1.13 kB
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()