-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for multiple events per endpoint #5703
Conversation
@@ -79,12 +79,16 @@ function createAttribute(string $databaseId, string $collectionId, Document $att | |||
throw new Exception(Exception::DATABASE_NOT_FOUND); | |||
} | |||
|
|||
$events->setContext('database', $db); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This context is required by some events so we have to make sure to set it before the DB operation so it's available in the handler.
$events->setContext('token', new Document([ | ||
'secret' => $loginSecret, | ||
])); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The unhashed secret is required in the event, so pass it to the handler using context.
app/init.php
Outdated
switch ($collection) { | ||
case 'users': | ||
if (!\str_starts_with($eventPattern, 'users.[userId]')) { | ||
$eventPattern = 'users.[userId]'; | ||
$eventPatternReady = false; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reverse engineering the event pattern given the collection feels a little hacky.
@@ -219,7 +219,7 @@ | |||
->setAttribute('password', Auth::passwordHash($password, Auth::DEFAULT_ALGO, Auth::DEFAULT_ALGO_OPTIONS)) | |||
->setAttribute('hash', Auth::DEFAULT_ALGO) | |||
->setAttribute('hashOptions', Auth::DEFAULT_ALGO_OPTIONS); | |||
$dbForProject->updateDocument('users', $profile->getId(), $profile); | |||
$dbForProject->silent(fn () => $dbForProject->updateDocument('users', $profile->getId(), $profile)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wrapping with silent to disable all listeners might be dangerous.
1ea5e58
to
138856f
Compare
We initially designed events to trigger via labels on the endpoint. the problem with this approach was triggering multiple events per endpoint became very messy.
138856f
to
bcb6b30
Compare
What does this PR do?
Trigger events using database listeners
We initially designed events to trigger via labels on the endpoint. the problem with this approach was triggering multiple events per endpoint became very messy.
Test Plan
TBD
Related PRs and Issues
users.*.create
when an Anonymous user is created #5198Checklist