Skip to content

Commit f8c96a9

Browse files
authored
Merge pull request #244 from authorizerdev/fix/remove-user-verification-request-when-deleted
fix: remove entries from otp + verification when user is deleted
2 parents 640bb8c + 837fc78 commit f8c96a9

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

server/constants/verification_types.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,14 @@ const (
1414
// VerificationTypeOTP is the otp verification type
1515
VerificationTypeOTP = "verify_otp"
1616
)
17+
18+
var (
19+
// VerificationTypes is slice of all verification types
20+
VerificationTypes = []string{
21+
VerificationTypeBasicAuthSignup,
22+
VerificationTypeMagicLinkLogin,
23+
VerificationTypeUpdateEmail,
24+
VerificationTypeForgotPassword,
25+
VerificationTypeInviteMember,
26+
}
27+
)

server/resolvers/delete_user.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,34 @@ func DeleteUserResolver(ctx context.Context, params model.DeleteUserInput) (*mod
5050
}
5151

5252
go func() {
53+
// delete otp for given email
54+
otp, err := db.Provider.GetOTPByEmail(ctx, user.Email)
55+
if err != nil {
56+
log.Debugf("Failed to get otp for given email (%s): %v", user.Email, err)
57+
// continue
58+
} else {
59+
err := db.Provider.DeleteOTP(ctx, otp)
60+
if err != nil {
61+
log.Debugf("Failed to delete otp for given email (%s): %v", user.Email, err)
62+
// continue
63+
}
64+
}
65+
66+
// delete verification requests for given email
67+
for _, vt := range constants.VerificationTypes {
68+
verificationRequest, err := db.Provider.GetVerificationRequestByEmail(ctx, user.Email, vt)
69+
if err != nil {
70+
log.Debug("Failed to get verification request for email: %s, verification_request_type: %s. %v", user.Email, vt, err)
71+
// continue
72+
} else {
73+
err := db.Provider.DeleteVerificationRequest(ctx, verificationRequest)
74+
if err != nil {
75+
log.Debug("Failed to DeleteVerificationRequest for email: %s, verification_request_type: %s. %v", user.Email, vt, err)
76+
// continue
77+
}
78+
}
79+
}
80+
5381
memorystore.Provider.DeleteAllUserSessions(user.ID)
5482
utils.RegisterEvent(ctx, constants.UserDeletedWebhookEvent, "", user)
5583
}()

0 commit comments

Comments
 (0)