feat(identity): confirm registration email atomically

This commit is contained in:
TakuyaYagam1 committed 2026-10-07 09:12:15 +03:00
1 parent 8e7ce8d71c
commit fade4e76e4
75 files changed
+4188 -403

No files matched your search

+21 -3
View File
@@ -72,12 +72,14 @@ func newIdentityHandler(
return nil, nil, fmt.Errorf("bootstrap.newIdentityHandler - create pool: %w", err)
}
transactor := postgres.NewTransactor(pool)
store := postgres.NewIdentityStore(pool)
credentials := identity.NewCredentials(hasher)
registration, err := identity.NewRegistration(identity.RegistrationDependencies{
Transactor: transactor,
ConsentTexts: postgres.NewConsentStore(pool),
Idempotency: postgres.NewIdentityStore(pool).IdempotencyRecords(),
Idempotency: store.IdempotencyRecords(),
Consents: consent.NewService(transactor, time.Now),
Credentials: identity.NewCredentials(hasher),
Credentials: credentials,
Mailer: notification.NewServiceMailer(notification.NewTemplateRenderer(renderer), account, time.Now),
Limiter: cache,
Keyring: keyring,
@@ -92,9 +94,25 @@ func newIdentityHandler(
pool.Close()
return nil, nil, fmt.Errorf("bootstrap.newIdentityHandler - create registration: %w", err)
}
confirmation, err := identity.NewEmailConfirmation(identity.ConfirmationDependencies{
Transactor: transactor,
Tokens: store.EmailTokens(),
Credentials: credentials,
Limiter: cache,
Keyring: keyring,
Clock: time.Now,
Metrics: metrics,
}, identity.ConfirmationSettings{
TokenHourlyLimit: identity.DefaultTokenHourlyLimit,
ClientHourlyLimit: int64(settings.IdentityClientHourlyLimit),
})
if err != nil {
pool.Close()
return nil, nil, fmt.Errorf("bootstrap.newIdentityHandler - create confirmation: %w", err)
}
// The HTTP server stops before this cleanup runs, so no request uses the
// pool while it closes.
return v1.NewIdentityHandler(registration), pool.Close, nil
return v1.NewIdentityHandler(registration, v1.WithEmailConfirmation(confirmation, settings.AppPublicURL)), pool.Close, nil
}
// newIdentityKeyring keys the idempotency scopes and rate limit buckets with