File size: 1,459 Bytes
4d5c005
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
from firebase_admin import auth
from typing import Dict, Optional

def create_user(email: str, password: str) -> Dict:
    """Create a new user with email and password"""
    try:
        user = auth.create_user(
            email=email,
            password=password,
            email_verified=False
        )
        return {
            "success": True,
            "user_id": user.uid,
            "email": user.email
        }
    except auth.EmailAlreadyExistsError:
        return {
            "success": False,
            "error": "Email already exists"
        }
    except Exception as e:
        return {
            "success": False,
            "error": str(e)
        }

def verify_token(id_token: str) -> Optional[Dict]:
    """Verify Firebase ID token"""
    try:
        decoded_token = auth.verify_id_token(id_token)
        return decoded_token
    except Exception as e:
        return None

def get_user_by_email(email: str) -> Optional[Dict]:
    """Get user by email"""
    try:
        user = auth.get_user_by_email(email)
        return {
            "user_id": user.uid,
            "email": user.email,
            "email_verified": user.email_verified
        }
    except auth.UserNotFoundError:
        return None
    except Exception:
        return None

def delete_user(uid: str) -> bool:
    """Delete a user by UID"""
    try:
        auth.delete_user(uid)
        return True
    except Exception:
        return False