Merge pull request #10224 from appwrite/pla-692

fix: create email target when using email otp registration
This commit is contained in:
Luke B. Silver 2025-07-29 10:27:43 +01:00 committed by GitHub
commit 3eb5cd80f3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 29 additions and 2 deletions

View file

@ -2239,7 +2239,30 @@ App::post('/v1/account/tokens/email')
]);
$user->removeAttribute('$sequence');
Authorization::skip(fn () => $dbForProject->createDocument('users', $user));
$user = Authorization::skip(fn () => $dbForProject->createDocument('users', $user));
try {
$target = Authorization::skip(fn () => $dbForProject->createDocument('targets', new Document([
'$permissions' => [
Permission::read(Role::user($user->getId())),
Permission::update(Role::user($user->getId())),
Permission::delete(Role::user($user->getId())),
],
'userId' => $user->getId(),
'userInternalId' => $user->getSequence(),
'providerType' => MESSAGE_TYPE_EMAIL,
'identifier' => $email,
])));
$user->setAttribute('targets', [...$user->getAttribute('targets', []), $target]);
} catch (Duplicate) {
$existingTarget = $dbForProject->findOne('targets', [
Query::equal('identifier', [$email]),
]);
if (!$existingTarget->isEmpty()) {
$user->setAttribute('targets', $existingTarget, Document::SET_TYPE_APPEND);
}
}
$dbForProject->purgeCachedDocument('users', $user->getId());
}
$tokenSecret = Auth::codeGenerator(6);

View file

@ -39,6 +39,8 @@ trait AccountBase
$this->assertEquals($response['body']['labels'], []);
$this->assertArrayHasKey('accessedAt', $response['body']);
$this->assertNotEmpty($response['body']['accessedAt']);
$this->assertArrayHasKey('targets', $response['body']);
$this->assertEquals($email, $response['body']['targets'][0]['identifier']);
/**
* Test for FAILURE
@ -159,7 +161,7 @@ trait AccountBase
'email' => 'otpuser@appwrite.io'
]);
$this->assertEquals(201, $response['headers']['status-code'], );
$this->assertEquals(201, $response['headers']['status-code']);
$this->assertNotEmpty($response['body']['$id']);
$this->assertNotEmpty($response['body']['$createdAt']);
$this->assertNotEmpty($response['body']['userId']);
@ -209,6 +211,8 @@ trait AccountBase
$this->assertEquals($userId, $response['body']['$id']);
$this->assertEquals($userId, $response['body']['$id']);
$this->assertTrue($response['body']['emailVerification']);
$this->assertArrayHasKey('targets', $response['body']);
$this->assertEquals('otpuser@appwrite.io', $response['body']['targets'][0]['identifier']);
$response = $this->client->call(Client::METHOD_POST, '/account/sessions/token', array_merge([
'origin' => 'http://localhost',