@@ -130,8 +130,17 @@ func LoginResolver(ctx context.Context, params model.LoginInput) (*model.AuthRes
130130 return res , fmt .Errorf (`email not verified` )
131131 } else {
132132 if vreq , err := db .Provider .GetVerificationRequestByEmail (ctx , email , constants .VerificationTypeBasicAuthSignup ); err == nil && vreq != nil {
133- log .Debug ("Verification request exists. Please verify email" )
134- return res , fmt .Errorf (`email verification pending` )
133+ // if verification request exists and not expired then return
134+ // if verification request exists and expired then delete it and proceed
135+ if vreq .ExpiresAt <= time .Now ().Unix () {
136+ if err := db .Provider .DeleteVerificationRequest (ctx , vreq ); err != nil {
137+ log .Debug ("Failed to delete verification request: " , err )
138+ // continue with the flow
139+ }
140+ } else {
141+ log .Debug ("Verification request exists. Please verify email" )
142+ return res , fmt .Errorf (`email verification pending` )
143+ }
135144 }
136145 expiresAt := time .Now ().Add (1 * time .Minute ).Unix ()
137146 otpData , err := generateOTP (expiresAt )
@@ -156,7 +165,7 @@ func LoginResolver(ctx context.Context, params model.LoginInput) (*model.AuthRes
156165 }()
157166 return & model.AuthResponse {
158167 Message : "Please check email inbox for the OTP" ,
159- ShouldShowEmailOtpScreen : refs .NewBoolRef (isMobileLogin ),
168+ ShouldShowEmailOtpScreen : refs .NewBoolRef (isEmailLogin ),
160169 }, nil
161170 }
162171 }
0 commit comments