Learning Ash after chatting with y’all at ElixirConf. Here’s my situation:
I have some tokens that can either expire or be revoked. I want to check if a specific token is valid based on its primary key.
This is the action:
read :valid? do
argument :jti, :string do
allow_nil? false
end
filter expr(jti == ^arg(:jti) and expires_at >= ^DateTime.utc_now() and is_nil(revoked_at))
end
I also have the following code interface on the resource.
define :valid?, action: :valid?
That returns, an {:ok, [%Token{}]}
which I can match on. That’s fine, and it works. I would like some better ergonomics though, so my question: is there a way to define a quick code interface that calls Ash.exists/2
like that, or do I need to define my own function for it?