Skip to content

Conversation

@cstockton
Copy link
Contributor

@cstockton cstockton commented May 14, 2025

Hooks Round 1

This PR will contain a series of commits preparing for the implementation of before & after user created hooks. It takes the feedback from #2012 into consideration.

Summary

prepare package structure:

  • update pkg internal/api to:
    • uses internal/hooks/v0hooks.Manager instead of internal/hooks/hooks.Manager aec5995
  • remove pkg internal/hooks/hooks.Manager 062da5d
  • add pkg internal/hooks/hookserrors 7e80afc
  • use pkg internal/hooks/hookserrors in internal/hooks/v0hooks 57744e8
  • update pkg internal/hooks/v0hooks with an Enabled method 16cc4c9

@cstockton cstockton requested a review from a team as a code owner May 14, 2025 17:36
@cstockton cstockton changed the title chore: rename packages to align with feedback from other PR chore: rename packages to remove versioning information May 14, 2025
@coveralls
Copy link

coveralls commented May 15, 2025

Pull Request Test Coverage Report for Build 15048831155

Details

  • 2 of 2 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 69.643%

Totals Coverage Status
Change from base Build 15005507419: 0.0%
Covered Lines: 10952
Relevant Lines: 15726

💛 - Coveralls

@cstockton cstockton self-assigned this May 15, 2025
@cstockton cstockton merged commit 066c53a into master May 15, 2025
5 checks passed
@cstockton cstockton deleted the cs/hooks-p1 branch May 15, 2025 15:28
@cstockton cstockton changed the title chore: rename packages to remove versioning information feat: hooks round 1 - prepare package structure May 16, 2025
cstockton added a commit that referenced this pull request May 19, 2025
…hooks (#2028)

## Hooks Round 3

This PR will contain a series of commits preparing for the
implementation of before & after user created hooks. It takes the
feedback from #2012 into
consideration.

### Summary

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`

### 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)

---------

Co-authored-by: Chris Stockton <chris.stockton@supabase.io>
cstockton added a commit that referenced this pull request May 19, 2025
…2025)

## Hooks Round 2

This PR will contain a series of commits preparing for the
implementation of before & after user created hooks. It takes the
feedback from #2012 into
consideration.

### Summary
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)

### 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)

---------

Co-authored-by: Chris Stockton <chris.stockton@supabase.io>
@cstockton cstockton restored the cs/hooks-p1 branch May 19, 2025 19:07
cstockton added a commit that referenced this pull request May 20, 2025
## Hooks Round 4

This PR will contain a series of commits preparing for the
implementation of before & after user created hooks. It takes the
feedback from #2012 into
consideration.

### Summary

[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/...`


### 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`

Co-authored-by: Chris Stockton <chris.stockton@supabase.io>
cstockton added a commit that referenced this pull request Jun 2, 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
This prepares packages to match with the agreed upon end state in
#2012

---------

Co-authored-by: Chris Stockton <chris.stockton@supabase.io>
Co-authored-by: Stojan Dimitrovski <sdimitrovski@gmail.com>
cemalkilic pushed a commit that referenced this pull request Aug 7, 2025
…2025)

## Hooks Round 2

This PR will contain a series of commits preparing for the
implementation of before & after user created hooks. It takes the
feedback from #2012 into
consideration.

### Summary
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)

### 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)

---------

Co-authored-by: Chris Stockton <chris.stockton@supabase.io>
cemalkilic pushed a commit that referenced this pull request Aug 7, 2025
## Hooks Round 4

This PR will contain a series of commits preparing for the
implementation of before & after user created hooks. It takes the
feedback from #2012 into
consideration.

### Summary

[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/...`


### 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`

Co-authored-by: Chris Stockton <chris.stockton@supabase.io>
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>
issuedat pushed a commit that referenced this pull request Sep 30, 2025
This prepares packages to match with the agreed upon end state in
#2012

---------

Co-authored-by: Chris Stockton <chris.stockton@supabase.io>
Co-authored-by: Stojan Dimitrovski <sdimitrovski@gmail.com>
issuedat pushed a commit that referenced this pull request Sep 30, 2025
…2025)

## Hooks Round 2

This PR will contain a series of commits preparing for the
implementation of before & after user created hooks. It takes the
feedback from #2012 into
consideration.

### Summary
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)

### 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)

---------

Co-authored-by: Chris Stockton <chris.stockton@supabase.io>
issuedat pushed a commit that referenced this pull request Sep 30, 2025
## Hooks Round 4

This PR will contain a series of commits preparing for the
implementation of before & after user created hooks. It takes the
feedback from #2012 into
consideration.

### Summary

[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/...`


### 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`

Co-authored-by: Chris Stockton <chris.stockton@supabase.io>
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants