Merge pull request #7280 from appwrite/fix-7190-user-identity-incorrect-user

Fix user identity attaching to wrong user
This commit is contained in:
Torsten Dittmann 2023-12-28 01:59:58 +01:00 committed by GitHub
commit 0fdc28e034
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -550,11 +550,19 @@ App::get('/v1/account/sessions/oauth2/:provider/redirect')
if (!$user->isEmpty()) {
$userId = $user->getId();
$identitiesWithMatchingEmail = $dbForProject->find('identities', [
$identityWithMatchingEmail = $dbForProject->findOne('identities', [
Query::equal('providerEmail', [$email]),
Query::notEqual('userId', $userId),
]);
if (!empty($identitiesWithMatchingEmail)) {
if (!empty($identityWithMatchingEmail)) {
throw new Exception(Exception::USER_ALREADY_EXISTS);
}
$userWithMatchingEmail = $dbForProject->find('users', [
Query::equal('email', [$email]),
Query::notEqual('$id', $userId),
]);
if (!empty($userWithMatchingEmail)) {
throw new Exception(Exception::USER_ALREADY_EXISTS);
}
}