ash_authentication/test/support/example/user_with_username.ex
James Harton a939dde9b9
feat(PasswordAuthentication): Registration and authentication with local credentials (#4)
This is missing a bunch of features that you probably want to use (eg confirmation, password resets), but it's a pretty good place to put a stake in the sand and say it works.
2022-10-25 11:07:07 +13:00

57 lines
1.1 KiB
Elixir

defmodule Example.UserWithUsername do
@moduledoc false
use Ash.Resource,
data_layer: AshPostgres.DataLayer,
extensions: [AshAuthentication, AshAuthentication.PasswordAuthentication]
@type t :: %__MODULE__{
id: Ecto.UUID.t(),
username: String.t(),
hashed_password: String.t(),
created_at: DateTime.t(),
updated_at: DateTime.t()
}
attributes do
uuid_primary_key(:id)
attribute(:username, :ci_string, allow_nil?: false)
attribute(:hashed_password, :string, allow_nil?: false, sensitive?: true)
create_timestamp(:created_at)
update_timestamp(:updated_at)
end
actions do
destroy :destroy do
primary? true
end
end
code_interface do
define_for(Example)
end
postgres do
table("user_with_username")
repo(Example.Repo)
end
authentication do
api(Example)
end
password_authentication do
identity_field(:username)
hashed_password_field(:hashed_password)
end
identities do
identity(:username, [:username])
end
tokens do
enabled?(true)
revocation_resource(Example.TokenRevocation)
end
end