-
Notifications
You must be signed in to change notification settings - Fork 566
feat: hooks round 5 (Option 2) - add before-user-created hook #2034
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
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This commit explores one possible implementation of this hook by:
- Adding a `triggerBeforeUserCreated` method to the `*API` object in `internal/api/hooks.go`
- Adding a `triggerBeforeUserCreatedExternal` method to the `*API` object in `internal/api/hooks.go`
- Updating callers of `signupNewUser` to first call `triggerBeforeUserCreated` in:
- internal/api/anonymous.go
- internal/api/external.go
- internal/api/invite.go
- internal/api/mail.go
- internal/api/signup.go
- Updating callers of `signupNewUser` to first call `triggerBeforeUserCreatedExternal` in:
- internal/api/external.go
- internal/api/samlacs.go
- internal/api/token_oidc.go
- internal/api/web3.go
- Add end to end tests in `internal/api/e2e_test.go`
Pull Request Test Coverage Report for Build 15329359133Warning: This coverage report may be inaccurate.This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.
Details
💛 - Coveralls |
Contributor
Author
|
Note: I'll improve test coverage if this implementation is approved. |
hf
approved these changes
May 23, 2025
Adding the e2e unit tests for the admin routes revealed a bug in the handling of invite type within adminGenerateLink.
Otherwise test ordering can change the test result.
cstockton
pushed a commit
that referenced
this pull request
Jun 5, 2025
🤖 I have created a release *beep* *boop* --- ## [2.175.0](v2.174.0...v2.175.0) (2025-06-03) ### Features * hooks round 5 (Option 2) - add before-user-created hook ([#2034](#2034)) ([b53f6b0](b53f6b0)) ### Bug Fixes * email-sendhook - bug in email change verification ([#2044](#2044)) ([be20654](be20654)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
cstockton
added a commit
that referenced
this pull request
Jun 16, 2025
cemalkilic
pushed a commit
that referenced
this pull request
Aug 7, 2025
## Hooks Round 5 - Option 2 This PR contains Option 1 for implementing the `before-user-created` hook. See #2032 for option 1. ### Summary This commit explores one possible implementation of this hook by: - Adding a `triggerBeforeUserCreated` method to the `*API` object in `internal/api/hooks.go` - Adding a `triggerBeforeUserCreatedExternal` method to the `*API` object in `internal/api/hooks.go` - Updating callers of `signupNewUser` to first call `triggerBeforeUserCreated` in: - internal/api/anonymous.go - internal/api/external.go - internal/api/invite.go - internal/api/mail.go - internal/api/signup.go - Updating callers of `signupNewUser` to first call `triggerBeforeUserCreatedExternal` in: - internal/api/external.go - internal/api/samlacs.go - internal/api/token_oidc.go - internal/api/web3.go - Add end to end tests in `internal/api/e2e_test.go` This has the benefit of being outside the transaction, but is a bit more complex. I make a best-effort to ensure I only trigger before-user-created when the user doesn't exist, but being outside the transaction there is a small chance for duplicate calls or calls that happen when a user already has been created. The main thought here is that we can document this behavior and the tradeoff is worth the benefits. ### Depends on [feat: hooks round 1](#2023) - prepare package structure * renamed pkg `internal/hooks/v0hooks/v0http` -> `internal/hooks/hookshttp` [8a398ab](8a398ab) * renamed pkg `internal/hooks/v0hooks/v0pgfunc` -> `internal/hooks/hookspgfunc` [8a398ab](8a398ab) * use pkg `internal/e2e` for test setup in: * pkg `internal/hooks/hookspgfunc` [4d60288](4d60288) * pkg `internal/hooks/v0hooks` [4a7432b](4a7432b) [feat: hooks round 2](#2025) - remove indirection and simplify error handling * update pkg `internal/api` to: * uses `internal/hooks/v0hooks.Manager` instead of `internal/hooks/hooks.Manager` [aec5995](aec5995) * remove pkg `internal/hooks/hooks.Manager` [062da5d](062da5d) * add pkg `internal/hooks/hookserrors` [7e80afc](7e80afc) * use pkg `internal/hooks/hookserrors` in `internal/hooks/v0hooks` [57744e8](57744e8) * update pkg `internal/hooks/v0hooks` with an `Enabled` method [16cc4c9](16cc4c9) [feat: hooks round 3](#2028) - begin adding the Before and After user created hooks * update pkg `internal/conf` [d5f5436](d5f5436) * add `BeforeUserCreated` and `AfterUserCreated` to `HookConfiguration` struct * add test cases for `EmailValidationBlockedMX` to restore 100% test coverage * update pkg `internal/hooks/v0hooks` [bd37fe2](bd37fe2) * add `BeforeUserCreated` method to `v0hooks.Manager` struct * add `AfterUserCreated` method to `v0hooks.Manager` struct * add tests to reach 100% coverage * add pkg `internal/e2e/e2ehooks` [903e623](903e623) * add `HookCall` to record calls to hooks * add `Hook` struct to hold `[]*HookCall` for a given hook name * add `HookRecorder` to hold one `Hook` object per hook name * add `Instance` struct to hold the `httptest.Server` and `HookRecorder` * add `AfterUserCreated` method to `v0hooks.Manager` struct * add tests to reach 100% coverage in all `internal/e2e` packages * update pkg `internal/hooks/v0hooks` [829aec6](829aec6) * fix struct and json tag to match to match the Metadata type * update pkg `internal/hooks/v0hooks` [ca67be0](ca67be0) * remove `BeforeUserCreated` and `AfterUserCreated` methods * add Before & After user created hooks in `InvokeHook` * update pkg `internal/e2e/e2eapi` [46c144e](46c144e) * add comments in IOError tests involving `http.RoundTripper` * update calls to `t.Fatal` to use `require` [feat: hooks round 4](#2030) - update tests to use require package * use pkg `require` for tests in: [f2b3600](f2b3600) * pkg `internal/e2e/...` * pkg `internal/hooks/...` --------- Co-authored-by: Chris Stockton <chris.stockton@supabase.io>
cemalkilic
pushed a commit
that referenced
this pull request
Aug 7, 2025
🤖 I have created a release *beep* *boop* --- ## [2.175.0](v2.174.0...v2.175.0) (2025-06-03) ### Features * hooks round 5 (Option 2) - add before-user-created hook ([#2034](#2034)) ([b53f6b0](b53f6b0)) ### Bug Fixes * email-sendhook - bug in email change verification ([#2044](#2044)) ([be20654](be20654)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
cemalkilic
pushed a commit
that referenced
this pull request
Aug 7, 2025
issuedat
pushed a commit
that referenced
this pull request
Sep 30, 2025
## Hooks Round 5 - Option 2 This PR contains Option 1 for implementing the `before-user-created` hook. See #2032 for option 1. ### Summary This commit explores one possible implementation of this hook by: - Adding a `triggerBeforeUserCreated` method to the `*API` object in `internal/api/hooks.go` - Adding a `triggerBeforeUserCreatedExternal` method to the `*API` object in `internal/api/hooks.go` - Updating callers of `signupNewUser` to first call `triggerBeforeUserCreated` in: - internal/api/anonymous.go - internal/api/external.go - internal/api/invite.go - internal/api/mail.go - internal/api/signup.go - Updating callers of `signupNewUser` to first call `triggerBeforeUserCreatedExternal` in: - internal/api/external.go - internal/api/samlacs.go - internal/api/token_oidc.go - internal/api/web3.go - Add end to end tests in `internal/api/e2e_test.go` This has the benefit of being outside the transaction, but is a bit more complex. I make a best-effort to ensure I only trigger before-user-created when the user doesn't exist, but being outside the transaction there is a small chance for duplicate calls or calls that happen when a user already has been created. The main thought here is that we can document this behavior and the tradeoff is worth the benefits. ### Depends on [feat: hooks round 1](#2023) - prepare package structure * renamed pkg `internal/hooks/v0hooks/v0http` -> `internal/hooks/hookshttp` [8a398ab](8a398ab) * renamed pkg `internal/hooks/v0hooks/v0pgfunc` -> `internal/hooks/hookspgfunc` [8a398ab](8a398ab) * use pkg `internal/e2e` for test setup in: * pkg `internal/hooks/hookspgfunc` [4d60288](4d60288) * pkg `internal/hooks/v0hooks` [4a7432b](4a7432b) [feat: hooks round 2](#2025) - remove indirection and simplify error handling * update pkg `internal/api` to: * uses `internal/hooks/v0hooks.Manager` instead of `internal/hooks/hooks.Manager` [aec5995](aec5995) * remove pkg `internal/hooks/hooks.Manager` [062da5d](062da5d) * add pkg `internal/hooks/hookserrors` [7e80afc](7e80afc) * use pkg `internal/hooks/hookserrors` in `internal/hooks/v0hooks` [57744e8](57744e8) * update pkg `internal/hooks/v0hooks` with an `Enabled` method [16cc4c9](16cc4c9) [feat: hooks round 3](#2028) - begin adding the Before and After user created hooks * update pkg `internal/conf` [d5f5436](d5f5436) * add `BeforeUserCreated` and `AfterUserCreated` to `HookConfiguration` struct * add test cases for `EmailValidationBlockedMX` to restore 100% test coverage * update pkg `internal/hooks/v0hooks` [bd37fe2](bd37fe2) * add `BeforeUserCreated` method to `v0hooks.Manager` struct * add `AfterUserCreated` method to `v0hooks.Manager` struct * add tests to reach 100% coverage * add pkg `internal/e2e/e2ehooks` [903e623](903e623) * add `HookCall` to record calls to hooks * add `Hook` struct to hold `[]*HookCall` for a given hook name * add `HookRecorder` to hold one `Hook` object per hook name * add `Instance` struct to hold the `httptest.Server` and `HookRecorder` * add `AfterUserCreated` method to `v0hooks.Manager` struct * add tests to reach 100% coverage in all `internal/e2e` packages * update pkg `internal/hooks/v0hooks` [829aec6](829aec6) * fix struct and json tag to match to match the Metadata type * update pkg `internal/hooks/v0hooks` [ca67be0](ca67be0) * remove `BeforeUserCreated` and `AfterUserCreated` methods * add Before & After user created hooks in `InvokeHook` * update pkg `internal/e2e/e2eapi` [46c144e](46c144e) * add comments in IOError tests involving `http.RoundTripper` * update calls to `t.Fatal` to use `require` [feat: hooks round 4](#2030) - update tests to use require package * use pkg `require` for tests in: [f2b3600](f2b3600) * pkg `internal/e2e/...` * pkg `internal/hooks/...` --------- Co-authored-by: Chris Stockton <chris.stockton@supabase.io>
issuedat
pushed a commit
that referenced
this pull request
Sep 30, 2025
🤖 I have created a release *beep* *boop* --- ## [2.175.0](v2.174.0...v2.175.0) (2025-06-03) ### Features * hooks round 5 (Option 2) - add before-user-created hook ([#2034](#2034)) ([b53f6b0](b53f6b0)) ### Bug Fixes * email-sendhook - bug in email change verification ([#2044](#2044)) ([be20654](be20654)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
issuedat
pushed a commit
that referenced
this pull request
Sep 30, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hooks Round 5 - Option 2
This PR contains Option 1 for implementing the
before-user-createdhook. See #2032 for option 1.Summary
This commit explores one possible implementation of this hook by:
triggerBeforeUserCreatedmethod to the*APIobject ininternal/api/hooks.gotriggerBeforeUserCreatedExternalmethod to the*APIobject ininternal/api/hooks.gosignupNewUserto first calltriggerBeforeUserCreatedin:signupNewUserto first calltriggerBeforeUserCreatedExternalin:internal/api/e2e_test.goThis has the benefit of being outside the transaction, but is a bit more complex. I make a best-effort to ensure I only trigger before-user-created when the user doesn't exist, but being outside the transaction there is a small chance for duplicate calls or calls that happen when a user already has been created. The main thought here is that we can document this behavior and the tradeoff is worth the benefits.
Depends on
feat: hooks round 1 - prepare package structure
internal/hooks/v0hooks/v0http->internal/hooks/hookshttp8a398abinternal/hooks/v0hooks/v0pgfunc->internal/hooks/hookspgfunc8a398abinternal/e2efor test setup in:internal/hooks/hookspgfunc4d60288internal/hooks/v0hooks4a7432bfeat: hooks round 2 - remove indirection and simplify error handling
internal/apito:internal/hooks/v0hooks.Managerinstead ofinternal/hooks/hooks.Manageraec5995internal/hooks/hooks.Manager062da5dinternal/hooks/hookserrors7e80afcinternal/hooks/hookserrorsininternal/hooks/v0hooks57744e8internal/hooks/v0hookswith anEnabledmethod 16cc4c9feat: hooks round 3 - begin adding the Before and After user created hooks
internal/confd5f5436BeforeUserCreatedandAfterUserCreatedtoHookConfigurationstructEmailValidationBlockedMXto restore 100% test coverageinternal/hooks/v0hooksbd37fe2BeforeUserCreatedmethod tov0hooks.ManagerstructAfterUserCreatedmethod tov0hooks.Managerstructinternal/e2e/e2ehooks903e623HookCallto record calls to hooksHookstruct to hold[]*HookCallfor a given hook nameHookRecorderto hold oneHookobject per hook nameInstancestruct to hold thehttptest.ServerandHookRecorderAfterUserCreatedmethod tov0hooks.Managerstructinternal/e2epackagesinternal/hooks/v0hooks829aec6internal/hooks/v0hooksca67be0BeforeUserCreatedandAfterUserCreatedmethodsInvokeHookinternal/e2e/e2eapi46c144ehttp.RoundTrippert.Fatalto userequirefeat: hooks round 4 - update tests to use require package
requirefor tests in: f2b3600internal/e2e/...internal/hooks/...