Skip to content

Commit f077d13

Browse files
committed
fix: create email identity when OAuth-only user sets a password
1 parent 7d90fb8 commit f077d13

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

internal/api/user.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,27 @@ func (a *API) UserUpdate(w http.ResponseWriter, r *http.Request) error {
225225
return terr
226226
}
227227

228+
if user.GetEmail() != "" {
229+
if _, terr = models.FindIdentityByIdAndProvider(tx, user.ID.String(), "email"); terr != nil {
230+
if !models.IsNotFoundError(terr) {
231+
return apierrors.NewInternalServerError("Error finding email identity").WithInternalError(terr)
232+
}
233+
emailIdentity, terr := models.NewIdentity(user, "email", map[string]interface{}{
234+
"sub": user.ID.String(),
235+
"email": user.GetEmail(),
236+
})
237+
if terr != nil {
238+
return apierrors.NewInternalServerError("Error creating email identity").WithInternalError(terr)
239+
}
240+
if terr := tx.Create(emailIdentity); terr != nil {
241+
return apierrors.NewInternalServerError("Error saving email identity").WithInternalError(terr)
242+
}
243+
if terr := user.UpdateAppMetaDataProviders(tx); terr != nil {
244+
return apierrors.NewInternalServerError("Error updating providers").WithInternalError(terr)
245+
}
246+
}
247+
}
248+
228249
// send a Password Changed email notification to the user to inform them that their password has been changed
229250
if config.Mailer.Notifications.PasswordChangedEnabled && user.GetEmail() != "" {
230251
if err := a.sendPasswordChangedNotification(r, tx, user); err != nil {

0 commit comments

Comments
 (0)