Skip to content

Commit

Permalink
fix(email webhook): check if user already has an email
Browse files Browse the repository at this point in the history
if user already has an email -> send EmailCreate Event
if user has no email -> send UserCreate Event
  • Loading branch information
Stefan Jacobi committed Jan 30, 2024
1 parent e62becb commit 03bfef9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
11 changes: 10 additions & 1 deletion backend/handler/email.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,16 @@ func (h *EmailHandler) Create(c echo.Context) error {
}

if !h.cfg.Emails.RequireVerification {
utils.NotifyUserChange(c, tx, h.persister, events.EmailCreate, userId)
var evt events.Event

if len(user.Emails) >= 1 {
evt = events.EmailCreate
} else {
evt = events.UserCreate
}

utils.NotifyUserChange(c, tx, h.persister, evt, userId)

}

return c.JSON(http.StatusOK, email)
Expand Down
10 changes: 9 additions & 1 deletion backend/handler/passcode.go
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,15 @@ func (h *PasscodeHandler) Finish(c echo.Context) error {

// notify about email verification result. Last step to prevent a trigger and rollback scenario
if h.cfg.Emails.RequireVerification && wasUnverified {
utils.NotifyUserChange(c, tx, h.persister, events.EmailCreate, user.ID)
var evt events.Event

if len(user.Emails) >= 1 {
evt = events.EmailCreate
} else {
evt = events.UserCreate
}

utils.NotifyUserChange(c, tx, h.persister, evt, user.ID)
}

return c.JSON(http.StatusOK, dto.PasscodeReturn{
Expand Down

0 comments on commit 03bfef9

Please sign in to comment.