Skip to content

Commit

Permalink
Merge pull request #460 from authorizerdev/fix-email-login
Browse files Browse the repository at this point in the history
fix: email login if email not verified
  • Loading branch information
lakhansamani authored Aug 24, 2024
2 parents 70f2de7 + 6acfd14 commit 10e9d8c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
3 changes: 2 additions & 1 deletion server/handlers/oauth_callback.go
Original file line number Diff line number Diff line change
Expand Up @@ -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."},
Expand Down
15 changes: 14 additions & 1 deletion server/resolvers/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,19 @@ 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 {
// 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)
if err != nil {
Expand All @@ -152,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 10e9d8c

Please sign in to comment.