Skip to content

Commit c6e0cbe

Browse files
authored
fix: add missing provider info to signedup audit logs (#2061)
## What kind of change does this PR introduce? Bug fix ## What is the current behavior? Currently, when users complete email or phone verification flows, the sign up audit logs are missing the `provider` field. ## What is the new behavior? - Audit logs now include the `provider` field for all signup actions - Added provider constants to improve code maintainability and prevent hardcoded strings
1 parent 8c4f6d9 commit c6e0cbe

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

internal/api/admin.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,7 @@ func (a *API) adminUserCreate(w http.ResponseWriter, r *http.Request) error {
461461
"user_id": user.ID,
462462
"user_email": user.Email,
463463
"user_phone": user.Phone,
464+
"provider": providers[0], // complying with the user.AppMetaData["provider"] field as above
464465
}); terr != nil {
465466
return terr
466467
}

internal/api/provider_constants.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package api
2+
3+
// Provider constants
4+
const (
5+
EmailProvider = "email"
6+
PhoneProvider = "phone"
7+
)

internal/api/verify.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,9 @@ func (a *API) signupVerify(r *http.Request, ctx context.Context, conn *storage.C
322322
}
323323
}
324324

325-
if terr = models.NewAuditLogEntry(r, tx, user, models.UserSignedUpAction, "", nil); terr != nil {
325+
if terr = models.NewAuditLogEntry(r, tx, user, models.UserSignedUpAction, "", map[string]interface{}{
326+
"provider": EmailProvider,
327+
}); terr != nil {
326328
return terr
327329
}
328330

@@ -357,7 +359,9 @@ func (a *API) recoverVerify(r *http.Request, conn *storage.Connection, user *mod
357359
return terr
358360
}
359361
if !user.IsConfirmed() {
360-
if terr = models.NewAuditLogEntry(r, tx, user, models.UserSignedUpAction, "", nil); terr != nil {
362+
if terr = models.NewAuditLogEntry(r, tx, user, models.UserSignedUpAction, "", map[string]interface{}{
363+
"provider": EmailProvider,
364+
}); terr != nil {
361365
return terr
362366
}
363367

@@ -383,7 +387,9 @@ func (a *API) smsVerify(r *http.Request, conn *storage.Connection, user *models.
383387
err := conn.Transaction(func(tx *storage.Connection) error {
384388

385389
if params.Type == smsVerification {
386-
if terr := models.NewAuditLogEntry(r, tx, user, models.UserSignedUpAction, "", nil); terr != nil {
390+
if terr := models.NewAuditLogEntry(r, tx, user, models.UserSignedUpAction, "", map[string]interface{}{
391+
"provider": PhoneProvider,
392+
}); terr != nil {
387393
return terr
388394
}
389395
if terr := user.ConfirmPhone(tx); terr != nil {

0 commit comments

Comments
 (0)