Coverage for app/services/register.py: 78%
21 statements
« prev ^ index » next coverage.py v7.8.2, created at 2025-06-02 23:27 +0000
« prev ^ index » next coverage.py v7.8.2, created at 2025-06-02 23:27 +0000
1from fastapi import HTTPException
2from supabase import create_client
3from dotenv import load_dotenv
4import os
6from app.core.exceptions import DatabaseQueryError, DatabaseSaveError, UnauthorizedError
8load_dotenv()
10def register_user(email: str, password: str):
11 if len(password) < 6:
12 raise HTTPException(400, "Password must be at least 6 characters.")
14 SUPABASE_URL = os.getenv("SUPABASE_URL")
15 SUPABASE_KEY = os.getenv("SUPABASE_KEY")
17 if not SUPABASE_URL or not SUPABASE_KEY: 17 ↛ 18line 17 didn't jump to line 18 because the condition on line 17 was never true
18 raise DatabaseQueryError("Supabase credentials missing.")
20 try:
21 supabase = create_client(SUPABASE_URL, SUPABASE_KEY)
22 response = supabase.auth.sign_up({
23 "email": email,
24 "password": password
25 })
27 if response.user is None: 27 ↛ 28line 27 didn't jump to line 28 because the condition on line 27 was never true
28 raise UnauthorizedError("Invalid email or password.")
30 return response
32 except Exception as e:
33 raise DatabaseSaveError(f"Failed to register {e}")