Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(jwt): add updated email on user create #1416

Merged
merged 1 commit into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions backend/dto/email.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ type EmailJwt struct {
}

func JwtFromEmailModel(email *models.Email) *EmailJwt {
if email == nil {
return nil
}

return &EmailJwt{
Address: email.Address,
IsPrimary: email.IsPrimary(),
Expand Down
8 changes: 7 additions & 1 deletion backend/handler/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ func (h *UserHandler) Create(c echo.Context) error {
if !h.cfg.Emails.RequireVerification {
// Assign the email address to the user because it's currently unassigned and email verification is turned off.
email.UserID = &newUser.ID

err = h.persister.GetEmailPersisterWithConnection(tx).Update(*email)
if err != nil {
return fmt.Errorf("failed to update email address: %w", err)
Expand Down Expand Up @@ -104,8 +105,13 @@ func (h *UserHandler) Create(c echo.Context) error {
return fmt.Errorf("failed to store primary email: %w", err)
}

emails, err := h.persister.GetEmailPersisterWithConnection(tx).FindByUserId(newUser.ID)
if err != nil {
return fmt.Errorf("failed to get email from db: %w", err)
}

var emailJwt *dto.EmailJwt
if e := newUser.Emails.GetPrimary(); e != nil {
if e := emails.GetPrimary(); e != nil {
emailJwt = dto.JwtFromEmailModel(e)
}

Expand Down
Loading