diff --git a/api/auth/login.py b/api/auth/login.py index 04d3b31..474b8b8 100644 --- a/api/auth/login.py +++ b/api/auth/login.py @@ -1,5 +1,5 @@ from flask import Blueprint, request, jsonify -from firebase_admin import auth +from firebase_admin import auth, firestore import urllib.parse login_bp = Blueprint("login", __name__) @@ -16,9 +16,24 @@ def login(): # Verify if the user exists in Firebase user = auth.get_user_by_email(email) + # Initialize Firestore client + db = firestore.client() + + # Check if the user document exists in Firestore + user_ref = db.collection('users').document(user.uid) + user_doc = user_ref.get() + + if not user_doc.exists: + # If user doesn't exist in Firestore, create a new user document + user_ref.set({ + 'email': email, + 'uid': user.uid, + 'messages': [] # Initialize an empty messages array + }) + # Generate a one-time login URL action_code_settings = { - "url": "http://localhost:8000/", + "url": "http://localhost:8000/", # URL to redirect to after successful login "handleCodeInApp": False, } login_url = auth.generate_email_action_link("SIGN_IN", email, action_code_settings)