🔥 initial commit 🔥

This commit is contained in:
2026-03-30 01:02:24 -04:00
commit cb179333f0
77 changed files with 6974 additions and 0 deletions

View File

@@ -0,0 +1,55 @@
defmodule Mixer.Accounts.ApiKey do
use Ash.Resource,
otp_app: :mixer,
domain: Mixer.Accounts,
data_layer: AshPostgres.DataLayer,
authorizers: [Ash.Policy.Authorizer]
postgres do
table "api_keys"
repo Mixer.Repo
end
actions do
defaults [:read, :destroy]
create :create do
primary? true
accept [:user_id, :expires_at]
change {AshAuthentication.Strategy.ApiKey.GenerateApiKey,
prefix: :mixer, hash: :api_key_hash}
end
end
policies do
bypass AshAuthentication.Checks.AshAuthenticationInteraction do
authorize_if always()
end
end
attributes do
uuid_primary_key :id
attribute :api_key_hash, :binary do
allow_nil? false
sensitive? true
end
attribute :expires_at, :utc_datetime_usec do
allow_nil? false
end
end
relationships do
belongs_to :user, Mixer.Accounts.User
end
calculations do
calculate :valid, :boolean, expr(expires_at > now())
end
identities do
identity :unique_api_key, [:api_key_hash]
end
end