From 03bfef9d190fdecade3051ed8d40ce3e2a8f13f7 Mon Sep 17 00:00:00 2001 From: Stefan Jacobi Date: Tue, 30 Jan 2024 11:18:59 +0100 Subject: [PATCH] fix(email webhook): check if user already has an email if user already has an email -> send EmailCreate Event if user has no email -> send UserCreate Event --- backend/handler/email.go | 11 ++++++++++- backend/handler/passcode.go | 10 +++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/backend/handler/email.go b/backend/handler/email.go index f63d4936c..76a8bbd81 100644 --- a/backend/handler/email.go +++ b/backend/handler/email.go @@ -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) diff --git a/backend/handler/passcode.go b/backend/handler/passcode.go index 2ea99ba69..3ec6c129b 100644 --- a/backend/handler/passcode.go +++ b/backend/handler/passcode.go @@ -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{