Skip to content

Commit

Permalink
gg
Browse files Browse the repository at this point in the history
  • Loading branch information
upayanmazumder committed Nov 29, 2024
1 parent 6aaa9da commit 7b3274d
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions api/auth/login.py
Original file line number Diff line number Diff line change
@@ -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__)
Expand All @@ -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)
Expand Down

0 comments on commit 7b3274d

Please sign in to comment.