Closed jagoanmamah closed 4 years ago
Is this when the user is created or is it for already existing users?
If it's for when the user is created, you can solve it with just the changeset:
defmodule MyApp.Users.User do
use Ecto.Schema
use Pow.Ecto.Schema
use PowAssent.Ecto.Schema
# ...
def user_identity_changeset(user_or_changeset, user_identity, attrs, user_id_attrs) do
user_or_changeset
|> pow_assent_user_identity_changeset(user_identity, attrs, user_id_attrs)
|> set_role(attrs)
end
defp set_role(changeset, attrs) do
changeset
|> Ecto.Changeset.get_field(:email)
|> email_is_admin?()
|> case do
true -> Ecto.Changeset.change(changeset, %{role: "admin"})
false -> changeset
end
end
defp email_is_admin?("admin@example.com"), do: true
defp email_is_admin?("admin2@example.com"), do: true
defp email_is_admin?(_any), do: false
end
I want to change the user's role for certain emails from Oauth, is that possible?