Coverage for app/services/login.py: 80%

21 statements  

« 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 

5 

6from app.core.exceptions import DatabaseQueryError, MissingCredentialsError, UnauthorizedError 

7 

8load_dotenv() 

9 

10def login_user(email:str, password: str): 

11 SUPABASE_URL = os.getenv("SUPABASE_URL") 

12 SUPABASE_KEY = os.getenv("SUPABASE_KEY") 

13 

14 if not SUPABASE_URL or not SUPABASE_KEY: 14 ↛ 15line 14 didn't jump to line 15 because the condition on line 14 was never true

15 raise MissingCredentialsError() 

16 

17 try: 

18 supabase = create_client(SUPABASE_URL, SUPABASE_KEY) 

19 

20 response = supabase.auth.sign_in_with_password({ 

21 "email": email, 

22 "password": password 

23 }) 

24 

25 if response.user is None: 25 ↛ 26line 25 didn't jump to line 26 because the condition on line 25 was never true

26 raise UnauthorizedError("Invalid email or password.") 

27 

28 return response 

29 

30 except UnauthorizedError: 

31 raise 

32 except Exception as e: 

33 raise DatabaseQueryError(f"Failed to login: {e}")