fix(auth): resolve login identities by active email and role

This commit is contained in:
2026-09-04 14:17:19 -03:00
parent e4db36e650
commit 99594b17e7
7 changed files with 28 additions and 8 deletions

View File

@@ -11,7 +11,7 @@ class AdminCredentialVerifier
public function verify(string $email, string $password): bool
{
$admin = User::query()
->where('email', mb_strtolower(trim($email)))
->where('active_email', mb_strtolower(trim($email)))
->where('rol_codigo', RoleCode::Admin->value)
->first();

View File

@@ -3,6 +3,7 @@
namespace App\Domains\Auth\Services;
use App\Domains\Auth\Models\User;
use App\Domains\Authorization\Enums\RoleCode;
use App\Domains\Notification\Events\UserRegistered;
use App\Domains\Tenant\Models\Tenant;
use App\Domains\Tenant\Support\TenantDomainNormalizer;
@@ -124,12 +125,12 @@ class GoogleAuthService
]);
}
$user = User::query()->where('google_id', $googleId)->first();
$user = User::query()->where('rol_codigo', RoleCode::User->value)->where('google_id', $googleId)->first();
if ($user) {
return $user;
}
$user = User::query()->where('email', $email)->first();
$user = User::query()->where('rol_codigo', RoleCode::User->value)->where('active_email', mb_strtolower(trim($email)))->first();
if ($user) {
$user->forceFill(['google_id' => $googleId])->save();

View File

@@ -78,6 +78,7 @@ class PasswordLoginService
string $password,
?string $ipAddress,
?string $userAgent,
RoleCode $role = RoleCode::Scanner,
): User {
return $this->authenticateUser(
$email,
@@ -85,10 +86,12 @@ class PasswordLoginService
null,
$ipAddress,
$userAgent,
null,
$role,
true,
PermissionCode::ScanTickets->value,
PasswordResetRequested::CHANNEL_SCANNER,
$role === RoleCode::AdminApp
? PasswordResetRequested::CHANNEL_ADMINAPP
: PasswordResetRequested::CHANNEL_SCANNER,
);
}
@@ -120,7 +123,7 @@ class PasswordLoginService
$passwordResetChannel,
): array {
$user = User::query()
->where('email', $normalizedEmail)
->where('active_email', $normalizedEmail)
->when(
$requiredRole !== null,
fn ($query) => $query->where('rol_codigo', $requiredRole->value),