dmitriid
dmitriid
AEAsh Elixir
Created by samoorai on 6/2/2023 in #support
Auth0 confusion
Of course 🙂
15 replies
AEAsh Elixir
Created by samoorai on 6/2/2023 in #support
Auth0 confusion
If I ever come around this, I should definitely do a PR against the docs
15 replies
AEAsh Elixir
Created by samoorai on 6/2/2023 in #support
Auth0 confusion
Yup, there's magic 🙂
15 replies
AEAsh Elixir
Created by samoorai on 6/2/2023 in #support
Auth0 confusion
No worries 🙂 It took me a while to understand how it's wired. I think that's all the modules you need
15 replies
AEAsh Elixir
Created by samoorai on 6/2/2023 in #support
Auth0 confusion
This is the full setup I have: https://gist.github.com/dmitriid/2ae3ae7737c640e9a5de42e79bef1bfb For
{:ash_authentication, "~> 3.11.1"},
{:ash_authentication_phoenix, "~> 1.7.2"},
{:ash_authentication, "~> 3.11.1"},
{:ash_authentication_phoenix, "~> 1.7.2"},
I hope this helps.
15 replies
AEAsh Elixir
Created by samoorai on 6/2/2023 in #support
Auth0 confusion
(it took me a while to wrap my head around, too 🙂 )
15 replies
AEAsh Elixir
Created by samoorai on 6/2/2023 in #support
Auth0 confusion
In router.ex: - Add use AshAuthentication.Phoenix.Router to the module - In whichever scope you use for auth, add the folliwing, e.g.
scope "/", YourAppWeb do
pipe_through :browser

#... whichever other routes you have ...

# Ash auth
sign_in_route()
sign_out_route AuthController
auth_routes_for YourApp.Module.Implementing.The.Auth, to: AuthController
reset_route []
# End Ash auth
end
scope "/", YourAppWeb do
pipe_through :browser

#... whichever other routes you have ...

# Ash auth
sign_in_route()
sign_out_route AuthController
auth_routes_for YourApp.Module.Implementing.The.Auth, to: AuthController
reset_route []
# End Ash auth
end
15 replies
AEAsh Elixir
Created by dmitriid on 4/10/2023 in #support
protocol Enumerable not implemented for #Ash.Changeset
@Zach Daniel thank you!
11 replies
AEAsh Elixir
Created by dmitriid on 4/10/2023 in #support
protocol Enumerable not implemented for #Ash.Changeset
Ahahaha. YES. I should read the docs more carefully
11 replies
AEAsh Elixir
Created by dmitriid on 4/10/2023 in #support
protocol Enumerable not implemented for #Ash.Changeset
That's probably the reason 🙂
11 replies
AEAsh Elixir
Created by dmitriid on 4/10/2023 in #support
protocol Enumerable not implemented for #Ash.Changeset
Oh my 😄
11 replies
AEAsh Elixir
Created by dmitriid on 4/10/2023 in #support
protocol Enumerable not implemented for #Ash.Changeset
Resource the second This one is somewhat trickier as it only contains relationships to other resources:
defmodule Telepai.Users.Bookmark do
actions do
defaults([:create, :read, :update, :destroy])
end

attributes do
integer_primary_key(:id)
end

relationships do
belongs_to :user, Telepai.Users.User do
allow_nil?(false)
end

belongs_to :history, Telepai.App.History do
api(Telepai.App)
allow_nil?(false)
end
end

code_interface do
define_for(__MODULE__)

# I tried both deifnitions, but with the same result :)
define(:new, action: :create, args: [:user, :history])
define(:create)
end
end
defmodule Telepai.Users.Bookmark do
actions do
defaults([:create, :read, :update, :destroy])
end

attributes do
integer_primary_key(:id)
end

relationships do
belongs_to :user, Telepai.Users.User do
allow_nil?(false)
end

belongs_to :history, Telepai.App.History do
api(Telepai.App)
allow_nil?(false)
end
end

code_interface do
define_for(__MODULE__)

# I tried both deifnitions, but with the same result :)
define(:new, action: :create, args: [:user, :history])
define(:create)
end
end
Using it:
> Telepai.Users.Bookmark.new(1, 1)
** (Protocol.UndefinedError) protocol Enumerable not implemented for #Ash.Changeset<action_type: :create, action: :create, attributes: %{}...
...
(ash 2.6.27) lib/ash/changeset/changeset.ex:998: Ash.Changeset.cast_params/3
(ash 2.6.27) lib/ash/changeset/changeset.ex:747: Ash.Changeset.do_for_action/4
(telepai 0.1.0) lib/ash/code_interface.ex:496: Telepai.Users.Bookmark.create/2
> Telepai.Users.Bookmark.new(1, 1)
** (Protocol.UndefinedError) protocol Enumerable not implemented for #Ash.Changeset<action_type: :create, action: :create, attributes: %{}...
...
(ash 2.6.27) lib/ash/changeset/changeset.ex:998: Ash.Changeset.cast_params/3
(ash 2.6.27) lib/ash/changeset/changeset.ex:747: Ash.Changeset.do_for_action/4
(telepai 0.1.0) lib/ash/code_interface.ex:496: Telepai.Users.Bookmark.create/2
11 replies
AEAsh Elixir
Created by dmitriid on 4/7/2023 in #support
Lookups/calcultions based on has_many relationships
Forgot to say thank you 🙂 Thank you!
27 replies
AEAsh Elixir
Created by dmitriid on 4/7/2023 in #support
Lookups/calcultions based on has_many relationships
No worries. This is brilliant anyway 🙂
27 replies
AEAsh Elixir
Created by dmitriid on 4/7/2023 in #support
Lookups/calcultions based on has_many relationships
And it looks like Ash.Query returns {:error, "is invalid"} in this case
27 replies
AEAsh Elixir
Created by dmitriid on 4/7/2023 in #support
Lookups/calcultions based on has_many relationships
argument :user_id, :uuid, allow_nil?: false This should be :integer because my ids are integers
27 replies
AEAsh Elixir
Created by dmitriid on 4/7/2023 in #support
Lookups/calcultions based on has_many relationships
I figured it out
27 replies
AEAsh Elixir
Created by dmitriid on 4/7/2023 in #support
Lookups/calcultions based on has_many relationships
Ah
27 replies
AEAsh Elixir
Created by dmitriid on 4/7/2023 in #support
Lookups/calcultions based on has_many relationships
Hmmm.. Something's funky 🙂
> Telepai.App.History |> Ash.Query.filter(expr(is_bookmarked(user_id: 1))) |> Telepai.App.read!()

** (Ash.Error.Unknown) Unknown Error

* filter: is invalid
> Telepai.App.History |> Ash.Query.filter(expr(is_bookmarked(user_id: 1))) |> Telepai.App.read!()

** (Ash.Error.Unknown) Unknown Error

* filter: is invalid
> Telepai.App.History |> Telepai.App.get!(1) |> Telepai.App.load!(is_bookmarked: %{user_id: 1})

AshPostgres.DataLayer.run_query/2, at: lib/data_layer.ex:613
** (BadMapError) expected a map, got: {:error, "is invalid"}
> Telepai.App.History |> Telepai.App.get!(1) |> Telepai.App.load!(is_bookmarked: %{user_id: 1})

AshPostgres.DataLayer.run_query/2, at: lib/data_layer.ex:613
** (BadMapError) expected a map, got: {:error, "is invalid"}
> Telepai.App.History |> Ash.Query.for_read(:read) |> Ash.Query.load(is_bookmarked: %{user_id: 1}) |> Telepai.App.read!()
** (RuntimeError) Telepai.GPT.read!/2 expected an %Ash.Query{} or an Ash Resource but instead got {:error, "is invalid"}
> Telepai.App.History |> Ash.Query.for_read(:read) |> Ash.Query.load(is_bookmarked: %{user_id: 1}) |> Telepai.App.read!()
** (RuntimeError) Telepai.GPT.read!/2 expected an %Ash.Query{} or an Ash Resource but instead got {:error, "is invalid"}
27 replies
AEAsh Elixir
Created by dmitriid on 4/7/2023 in #support
Lookups/calcultions based on has_many relationships
Ah. Brilliant. This looks exactly like what I'd want. Only now I have no idea how to load this calculation with the arguments 🙂
27 replies