Skip to content

Commit

Permalink
fix: reduce size of PR
Browse files Browse the repository at this point in the history
  • Loading branch information
J0 committed Jun 18, 2024
1 parent 37a20cd commit cc4d1db
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
3 changes: 1 addition & 2 deletions internal/api/recover.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ func (p *RecoverParams) Validate() error {
// Recover sends a recovery email
func (a *API) Recover(w http.ResponseWriter, r *http.Request) error {
ctx := r.Context()
config := a.config
db := a.db.WithContext(ctx)
params := &RecoverParams{}
if err := retrieveRequestParams(r, params); err != nil {
Expand Down Expand Up @@ -69,7 +68,7 @@ func (a *API) Recover(w http.ResponseWriter, r *http.Request) error {
})
if err != nil {
if errors.Is(err, MaxFrequencyLimitError) {
return tooManyRequestsError(ErrorCodeOverEmailSendRateLimit, generateFrequencyLimitErrorMessage(user.RecoverySentAt, config.SMTP.MaxFrequency))
return tooManyRequestsError(ErrorCodeOverEmailSendRateLimit, "For security purposes, you can only request this once every 60 seconds")
}
return internalServerError("Unable to process request").WithInternalError(err)
}
Expand Down
10 changes: 4 additions & 6 deletions internal/api/resend.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package api
import (
"errors"
"net/http"
"time"

"github.com/supabase/auth/internal/api/sms_provider"
"github.com/supabase/auth/internal/conf"
Expand Down Expand Up @@ -153,15 +154,12 @@ func (a *API) Resend(w http.ResponseWriter, r *http.Request) error {
if err != nil {
if errors.Is(err, MaxFrequencyLimitError) {
reason := ErrorCodeOverEmailSendRateLimit
if params.Type == smsVerification {
if params.Type == smsVerification || params.Type == phoneChangeVerification {
reason = ErrorCodeOverSMSSendRateLimit
return tooManyRequestsError(reason, generateFrequencyLimitErrorMessage(user.ConfirmationSentAt, config.Sms.MaxFrequency))
} else if params.Type == phoneChangeVerification {
reason = ErrorCodeOverSMSSendRateLimit
return tooManyRequestsError(reason, generateFrequencyLimitErrorMessage(user.PhoneChangeSentAt, config.Sms.MaxFrequency))
}

return tooManyRequestsError(reason, generateFrequencyLimitErrorMessage(user.ConfirmationSentAt, config.SMTP.MaxFrequency))
until := time.Until(user.ConfirmationSentAt.Add(config.SMTP.MaxFrequency)) / time.Second
return tooManyRequestsError(reason, "For security purposes, you can only request this once every %d seconds.", until)
}
return internalServerError("Unable to process request").WithInternalError(err)
}
Expand Down

0 comments on commit cc4d1db

Please sign in to comment.