Skip to content

Commit

Permalink
sends otp only if verification req is expired
Browse files Browse the repository at this point in the history
  • Loading branch information
lakhansamani committed Aug 24, 2024
1 parent e8d9ea2 commit 2c75a01
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions server/resolvers/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
}
}
Expand Down

0 comments on commit 2c75a01

Please sign in to comment.