-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauth.py
More file actions
43 lines (35 loc) · 1.23 KB
/
Copy pathauth.py
File metadata and controls
43 lines (35 loc) · 1.23 KB
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
from flask import Blueprint, request, jsonify
from firebase_admin import auth
from firebase_config import db
auth_bp = Blueprint('auth', __name__)
@auth_bp.route('/signup', methods=['POST'])
def signup_user():
data = request.json
name = data.get('name')
nickname = data.get('nickname')
phone = data.get('phone')
try:
user = auth.create_user(
display_name=nickname,
phone_number=phone,
)
# Optional: Save more details to Firestore under 'users'
db.collection('users').document(user.uid).set({
'name': name,
'nickname': nickname,
'phone': phone
})
return jsonify({'message': 'User created', 'uid': user.uid}), 201
except Exception as e:
return jsonify({'error': str(e)}), 500
@auth_bp.route('/login', methods=['POST'])
def login_user():
data = request.json
phone = data.get('phone')
try:
user = auth.get_user_by_phone_number(phone)
return jsonify({'message': 'User found', 'uid': user.uid}), 200
except auth.UserNotFoundError:
return jsonify({'error': 'User not found. Please sign up first.'}), 404
except Exception as e:
return jsonify({'error': str(e)}), 500