From e8d9ea2dd644fc4ca3f06bbc59f2bcd23aa027d6 Mon Sep 17 00:00:00 2001 From: Lakhan Samani Date: Sat, 24 Aug 2024 09:01:55 +0530 Subject: [PATCH 1/3] fix: email login if email not verified Resolves #458 --- server/resolvers/login.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/server/resolvers/login.go b/server/resolvers/login.go index 89b1ba232..1e3fb2d07 100644 --- a/server/resolvers/login.go +++ b/server/resolvers/login.go @@ -129,6 +129,10 @@ func LoginResolver(ctx context.Context, params model.LoginInput) (*model.AuthRes log.Debug("User email is not verified and email service is not enabled") return res, fmt.Errorf(`email not verified`) } else { + if vreq, err := db.Provider.GetVerificationRequestByEmail(ctx, email, constants.VerificationTypeBasicAuthSignup); err == nil && vreq != nil { + log.Debug("Verification request exists. Please verify email") + return res, fmt.Errorf(`email verification pending`) + } expiresAt := time.Now().Add(1 * time.Minute).Unix() otpData, err := generateOTP(expiresAt) if err != nil { From 2c75a01e95ac1c3fae04fa364a5b614902bb100e Mon Sep 17 00:00:00 2001 From: Lakhan Samani Date: Sat, 24 Aug 2024 09:10:24 +0530 Subject: [PATCH 2/3] sends otp only if verification req is expired --- server/resolvers/login.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/server/resolvers/login.go b/server/resolvers/login.go index 1e3fb2d07..159c18e26 100644 --- a/server/resolvers/login.go +++ b/server/resolvers/login.go @@ -130,8 +130,17 @@ func LoginResolver(ctx context.Context, params model.LoginInput) (*model.AuthRes return res, fmt.Errorf(`email not verified`) } else { if vreq, err := db.Provider.GetVerificationRequestByEmail(ctx, email, constants.VerificationTypeBasicAuthSignup); err == nil && vreq != nil { - log.Debug("Verification request exists. Please verify email") - return res, fmt.Errorf(`email verification pending`) + // if verification request exists and not expired then return + // if verification request exists and expired then delete it and proceed + if vreq.ExpiresAt <= time.Now().Unix() { + if err := db.Provider.DeleteVerificationRequest(ctx, vreq); err != nil { + log.Debug("Failed to delete verification request: ", err) + // continue with the flow + } + } else { + log.Debug("Verification request exists. Please verify email") + return res, fmt.Errorf(`email verification pending`) + } } expiresAt := time.Now().Add(1 * time.Minute).Unix() otpData, err := generateOTP(expiresAt) @@ -156,7 +165,7 @@ func LoginResolver(ctx context.Context, params model.LoginInput) (*model.AuthRes }() return &model.AuthResponse{ Message: "Please check email inbox for the OTP", - ShouldShowEmailOtpScreen: refs.NewBoolRef(isMobileLogin), + ShouldShowEmailOtpScreen: refs.NewBoolRef(isEmailLogin), }, nil } } From 6acfd142f2157084c4e40db3b3e4e4ceb3c53c8a Mon Sep 17 00:00:00 2001 From: Lakhan Samani Date: Sat, 24 Aug 2024 09:37:57 +0530 Subject: [PATCH 3/3] add debug log --- server/handlers/oauth_callback.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/server/handlers/oauth_callback.go b/server/handlers/oauth_callback.go index ce0b53c3c..f3610f47c 100644 --- a/server/handlers/oauth_callback.go +++ b/server/handlers/oauth_callback.go @@ -112,7 +112,8 @@ func OAuthCallbackHandler() gin.HandlerFunc { ctx.JSON(400, gin.H{"error": err.Error()}) return } - if user == nil{ + if user == nil { + log.Debug("User is nil") ctx.JSON( 500, gin.H{"error": "Something Went Wrong. Please Try Again."},