feat(auth): return last_name in TokenResponse and resolve Google full name properly
This commit is contained in:
parent
352830a66d
commit
bb1c4a3c9d
1 changed files with 25 additions and 3 deletions
|
|
@ -61,6 +61,7 @@ class TokenResponse(BaseModel):
|
||||||
customer_id: str
|
customer_id: str
|
||||||
email: str
|
email: str
|
||||||
first_name: str
|
first_name: str
|
||||||
|
last_name: Optional[str] = None
|
||||||
|
|
||||||
# --- Helper Functions ---
|
# --- Helper Functions ---
|
||||||
|
|
||||||
|
|
@ -106,7 +107,8 @@ def issue_tokens(db: Session, customer: EcomCustomer, response: Response, token_
|
||||||
access_token=access_token,
|
access_token=access_token,
|
||||||
customer_id=customer.customer_id,
|
customer_id=customer.customer_id,
|
||||||
email=customer.email,
|
email=customer.email,
|
||||||
first_name=customer.first_name
|
first_name=customer.first_name,
|
||||||
|
last_name=customer.last_name
|
||||||
)
|
)
|
||||||
|
|
||||||
def perform_guest_cart_merge(db: Session, customer_id: str, guest_session_id: Optional[str]):
|
def perform_guest_cart_merge(db: Session, customer_id: str, guest_session_id: Optional[str]):
|
||||||
|
|
@ -411,8 +413,16 @@ def google_oauth_callback(
|
||||||
)
|
)
|
||||||
|
|
||||||
# First-time registration with Google
|
# First-time registration with Google
|
||||||
first_name = idinfo.get("given_name", "Google")
|
full_name = idinfo.get("name") or ""
|
||||||
last_name = idinfo.get("family_name", "User")
|
given = idinfo.get("given_name")
|
||||||
|
family = idinfo.get("family_name")
|
||||||
|
if not given and full_name:
|
||||||
|
parts = full_name.strip().split(" ", 1)
|
||||||
|
first_name = parts[0]
|
||||||
|
last_name = parts[1] if len(parts) > 1 else ""
|
||||||
|
else:
|
||||||
|
first_name = given or full_name or "Google"
|
||||||
|
last_name = family or ""
|
||||||
|
|
||||||
customer = EcomCustomer(
|
customer = EcomCustomer(
|
||||||
customer_id=str(ulid.ULID()),
|
customer_id=str(ulid.ULID()),
|
||||||
|
|
@ -432,6 +442,18 @@ def google_oauth_callback(
|
||||||
customer.last_login = datetime.now(timezone.utc).replace(tzinfo=None)
|
customer.last_login = datetime.now(timezone.utc).replace(tzinfo=None)
|
||||||
if picture:
|
if picture:
|
||||||
customer.profile_picture = picture
|
customer.profile_picture = picture
|
||||||
|
given = idinfo.get("given_name")
|
||||||
|
family = idinfo.get("family_name")
|
||||||
|
full_name = idinfo.get("name") or ""
|
||||||
|
if given and (not customer.first_name or customer.first_name == "Google"):
|
||||||
|
customer.first_name = given
|
||||||
|
elif full_name and (not customer.first_name or customer.first_name == "Google"):
|
||||||
|
parts = full_name.strip().split(" ", 1)
|
||||||
|
customer.first_name = parts[0]
|
||||||
|
if len(parts) > 1 and not customer.last_name:
|
||||||
|
customer.last_name = parts[1]
|
||||||
|
if family and not customer.last_name:
|
||||||
|
customer.last_name = family
|
||||||
db.commit()
|
db.commit()
|
||||||
|
|
||||||
# Idempotent and transactional guest cart merge
|
# Idempotent and transactional guest cart merge
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue