File size: 1,006 Bytes
1f1b4db
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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