This commit is contained in:
2026-06-23 17:36:20 +03:30
parent 1a0645daef
commit a6f41ed6f8
+15 -2
View File
@@ -44,10 +44,16 @@ public function loginV2(Request $request)
$user = User::where('identifier', $response['uuid'])->first();
}
// If not found, try by email
if (!$user) {
// Then by email — only when an email exists. (where('email', null) would
// match an arbitrary mobile-only user and cross-link the wrong account.)
if (!$user && !empty($response['email'])) {
$user = User::where('email', $response['email'])->first();
}
// Finally by mobile, so mobile-only users reconnect to their account
if (!$user && !empty($response['mobile'])) {
$user = User::where('mobile', $response['mobile'])->first();
}
$mobile = $response['mobile'] ?? null;
// If mobile already exists, set it null to avoid duplicate error
@@ -68,6 +74,9 @@ public function loginV2(Request $request)
]);
} else {
// Only update name and mobile for existing user
// Keep the local identifier aligned with the current approagency uuid
// (e.g. when the user was matched by mobile, not identifier).
$user->identifier = $response['uuid'] ?? $user->identifier;
$user->first_name = $response['first_name'] ?? $user->first_name;
$user->last_name = $response['last_name'] ?? $user->last_name;
// $user->name = trim(($response['first_name'] ?? '') . ' ' . ($response['last_name'] ?? ''));
@@ -106,6 +115,9 @@ private function syncUserFromStatus(array $response, ?User $user = null): User
if (!$user && !empty($response['email'])) {
$user = User::where('email', $response['email'])->first();
}
if (!$user && !empty($response['mobile'])) {
$user = User::where('mobile', $response['mobile'])->first();
}
}
$mobile = $response['mobile'] ?? null;
@@ -127,6 +139,7 @@ private function syncUserFromStatus(array $response, ?User $user = null): User
]);
} else {
// update existing
$user->identifier = $response['uuid'] ?? $user->identifier;
$user->first_name = $response['first_name'] ?? $user->first_name;
$user->last_name = $response['last_name'] ?? $user->last_name;
$user->mobile = $mobile ?? $user->mobile;