From 4fc388186ac7e7a9a32ca9b963a83d6ac2eb7603 Mon Sep 17 00:00:00 2001 From: Kang Ming Date: Wed, 3 Apr 2024 17:02:22 +0800 Subject: [PATCH] fix: generate signup link should not error (#1514) ## What kind of change does this PR introduce? * Fixes an error introduced in #1377 where generating a signup link for a new user results in a "User with this email not found" error ## What is the current behavior? Please link any relevant issues here. ## What is the new behavior? Feel free to include screenshots if it includes visual changes. ## Additional context Add any other context or screenshots. --- internal/api/mail.go | 6 +++--- internal/api/mail_test.go | 14 +++++++++++++- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/internal/api/mail.go b/internal/api/mail.go index 9b7d8dbff..ce150882a 100644 --- a/internal/api/mail.go +++ b/internal/api/mail.go @@ -1,11 +1,12 @@ package api import ( - mail "github.com/supabase/auth/internal/mailer" "net/http" "strings" "time" + mail "github.com/supabase/auth/internal/mailer" + "github.com/badoux/checkmail" "github.com/fatih/structs" "github.com/pkg/errors" @@ -72,8 +73,7 @@ func (a *API) adminGenerateLink(w http.ResponseWriter, r *http.Request) error { // password generation must always succeed panic(err) } - - default: + case mail.RecoveryVerification, mail.EmailChangeCurrentVerification, mail.EmailChangeNewVerification: return notFoundError(ErrorCodeUserNotFound, "User with this email not found") } } else { diff --git a/internal/api/mail_test.go b/internal/api/mail_test.go index f61e0ebff..6063a9a6b 100644 --- a/internal/api/mail_test.go +++ b/internal/api/mail_test.go @@ -65,7 +65,19 @@ func (ts *MailTestSuite) TestGenerateLink() { ExpectedResponse map[string]interface{} }{ { - Desc: "Generate signup link", + Desc: "Generate signup link for new user", + Body: GenerateLinkParams{ + Email: "new_user@example.com", + Password: "secret123", + Type: "signup", + }, + ExpectedCode: http.StatusOK, + ExpectedResponse: map[string]interface{}{ + "redirect_to": ts.Config.SiteURL, + }, + }, + { + Desc: "Generate signup link for existing user", Body: GenerateLinkParams{ Email: "test@example.com", Password: "secret123",