csos95
csos95
AEAsh Elixir
Created by csos95 on 1/27/2023 in #support
Issues using AshAuthentication's sign_in_with_password action with AshGraphql
defmodule Coruscant.Accounts.User do
use Ash.Resource,
data_layer: AshPostgres.DataLayer,
extensions: [AshAuthentication, AshGraphql.Resource]

code_interface do
define_for Coruscant.Accounts
define :register_with_password, args: [:name, :password, :password_confirmation]
define :sign_in_with_password, args: [:name, :password]
end

graphql do
type :user

queries do
list :list_users, :read
end

mutations do
create :register, :register_with_password
# if this is uncommented it causes a compile error
# create :sign_in, :sign_in_with_password
end
end

actions do
defaults [:read]
end

attributes do
uuid_primary_key :id

attribute :name, :string do
allow_nil? false
end

attribute :hashed_password, :string do
allow_nil? false
sensitive? true
private? true
end
end

authentication do
api Coruscant.Accounts

strategies do
password :password do
identity_field :name
end
end

tokens do
enabled? true
token_resource Coruscant.Accounts.Token

signing_secret fn _, _ ->
Application.fetch_env(:coruscant, :token_signing_secret)
end
end
end

postgres do
table "users"
repo Coruscant.Repo
end

identities do
identity :unique_name, [:name]
end
end
defmodule Coruscant.Accounts.User do
use Ash.Resource,
data_layer: AshPostgres.DataLayer,
extensions: [AshAuthentication, AshGraphql.Resource]

code_interface do
define_for Coruscant.Accounts
define :register_with_password, args: [:name, :password, :password_confirmation]
define :sign_in_with_password, args: [:name, :password]
end

graphql do
type :user

queries do
list :list_users, :read
end

mutations do
create :register, :register_with_password
# if this is uncommented it causes a compile error
# create :sign_in, :sign_in_with_password
end
end

actions do
defaults [:read]
end

attributes do
uuid_primary_key :id

attribute :name, :string do
allow_nil? false
end

attribute :hashed_password, :string do
allow_nil? false
sensitive? true
private? true
end
end

authentication do
api Coruscant.Accounts

strategies do
password :password do
identity_field :name
end
end

tokens do
enabled? true
token_resource Coruscant.Accounts.Token

signing_secret fn _, _ ->
Application.fetch_env(:coruscant, :token_signing_secret)
end
end
end

postgres do
table "users"
repo Coruscant.Repo
end

identities do
identity :unique_name, [:name]
end
end
127 replies