fix: remove entries from otp + verification when user is deleted

Resolves #234
This commit is contained in:
Lakhan Samani 2022-09-27 00:27:36 +05:30
parent 640bb8c9ed
commit 837fc781de
2 changed files with 39 additions and 0 deletions

View File

@ -14,3 +14,14 @@ const (
// VerificationTypeOTP is the otp verification type // VerificationTypeOTP is the otp verification type
VerificationTypeOTP = "verify_otp" VerificationTypeOTP = "verify_otp"
) )
var (
// VerificationTypes is slice of all verification types
VerificationTypes = []string{
VerificationTypeBasicAuthSignup,
VerificationTypeMagicLinkLogin,
VerificationTypeUpdateEmail,
VerificationTypeForgotPassword,
VerificationTypeInviteMember,
}
)

View File

@ -50,6 +50,34 @@ func DeleteUserResolver(ctx context.Context, params model.DeleteUserInput) (*mod
} }
go func() { go func() {
// delete otp for given email
otp, err := db.Provider.GetOTPByEmail(ctx, user.Email)
if err != nil {
log.Debugf("Failed to get otp for given email (%s): %v", user.Email, err)
// continue
} else {
err := db.Provider.DeleteOTP(ctx, otp)
if err != nil {
log.Debugf("Failed to delete otp for given email (%s): %v", user.Email, err)
// continue
}
}
// delete verification requests for given email
for _, vt := range constants.VerificationTypes {
verificationRequest, err := db.Provider.GetVerificationRequestByEmail(ctx, user.Email, vt)
if err != nil {
log.Debug("Failed to get verification request for email: %s, verification_request_type: %s. %v", user.Email, vt, err)
// continue
} else {
err := db.Provider.DeleteVerificationRequest(ctx, verificationRequest)
if err != nil {
log.Debug("Failed to DeleteVerificationRequest for email: %s, verification_request_type: %s. %v", user.Email, vt, err)
// continue
}
}
}
memorystore.Provider.DeleteAllUserSessions(user.ID) memorystore.Provider.DeleteAllUserSessions(user.ID)
utils.RegisterEvent(ctx, constants.UserDeletedWebhookEvent, "", user) utils.RegisterEvent(ctx, constants.UserDeletedWebhookEvent, "", user)
}() }()