TEST_TUTOR / main.py
XThomasBU's picture
Update main.py
514b7f0 verified
import chainlit as cl
import base64
import json
from typing import Any, Dict, no_type_check
from typing import Optional
@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)
print("\n\n")
print("USER")
print(decoded_user_info["email"])
print("\n\n")
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()