mirror of
https://github.com/teamhanko/hanko.git
synced 2025-10-27 06:06:54 +08:00
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
This commit is contained in:
@ -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)
|
||||
|
||||
@ -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{
|
||||
|
||||
Reference in New Issue
Block a user