test / auth /register.py
gaoqilan's picture
Upload 103 files
1f1b4db verified
from utils.http import HTTPClient
from config.constants import API_URL
class Registration:
@staticmethod
async def register_user(firebase_token: str) -> str:
"""
Register user with firebase token and return API key
"""
headers = {
"User-Agent": "Go-http-client/1.1",
"Content-Type": "application/json",
"Accept-Encoding": "gzip",
}
data = {"firebase_id_token": firebase_token}
response = await HTTPClient().post(
f"{API_URL}/register_user/", headers=headers, default_headers=False, json=data, verify=False
)
if response.status_code != 200:
print(response.text)
raise Exception(f"Registration failed: {response.status_code}")
response_json = response.json()
api_key = response_json.get("api_key")
if not api_key:
raise Exception("No API key in response")
return api_key