persona icon indicating copy to clipboard operation
persona copied to clipboard

make runValidation in updateProfile

Open yariksav opened this issue 7 years ago • 4 comments

It would be great to have auto validation on existance uids in updateProfile, same as runValidation in register https://github.com/adonisjs/adonis-persona/blob/b28c5231c4355f8a11a2e357e90807ffd77ab70b/src/Persona.js#L632

yariksav avatar Jul 17 '18 22:07 yariksav

Hey @yariksav! 👋

Sorry for getting late on this, what's your issue?

RomainLanz avatar Aug 10 '18 14:08 RomainLanz

Because when I execute Persona.updateProfile(auth.user, payload) where username was changed to already exists in other user i receive sql error: update "users" set "username"= $1, "created_at" = $2, "updated_at" = $3 where "id" = $4 - duplicate key value violates unique constraint "users_username_unique"

yariksav avatar Aug 10 '18 18:08 yariksav

You need to run yourself validation on this query. We cannot run validation here because we don't know what you want to change.

Also, you need to handle this type of exception, since between the validation and the save someone could make the change.

RomainLanz avatar Aug 10 '18 20:08 RomainLanz

I believe, Persona can be improve here. Let me create an RFC explaining the changes we can make to improve the overall flow of persona including https://github.com/adonisjs/adonis-persona/issues/11

thetutlage avatar Aug 12 '18 11:08 thetutlage