When trying to register with a user that is already taken you will arrive at a phoenix error page.
This should instead be handled by the changeset and flash this error.
This can be easily fixed by adding a unique constrain on :email in the user model here
In other words change this:
def changeset(struct, params \\ %{}) do
struct
|> cast(params, @required_fields ++ @optional_fields)
|> validate_required(@required_fields)
end
to this:
def changeset(struct, params \\ %{}) do
struct
|> cast(params, @required_fields ++ @optional_fields)
|> validate_required(@required_fields)
|> unique_constraint(:email)
end
When trying to register with a user that is already taken you will arrive at a phoenix error page.
This should instead be handled by the
changesetandflashthis error.This can be easily fixed by adding a unique constrain on
:emailin the user model hereIn other words change this:
to this: