Logging in via the API

Working through authorizing api access for authentication and cant seem to login via the api, however I am able to create an account via the api
No description
No description
6 Replies
Shaba
ShabaOP4mo ago
My accounts domain configuration:
defmodule Tunez.Accounts do
use Ash.Domain, otp_app: :tunez, extensions: [AshJsonApi.Domain]

json_api do
routes do
base_route "/users", Tunez.Accounts.User do
post :register_with_password do
route "/register"

metadata fn _subject, user, _request ->
%{token: user.__metadata__.token}
end
end

post :sign_in_with_password do
route "/sign-in"

metadata fn _subject, user, _request ->
%{token: user.__metadata__.token}
end
end
end
end
end

resources do
resource Tunez.Accounts.Token
resource Tunez.Accounts.User
end
end
defmodule Tunez.Accounts do
use Ash.Domain, otp_app: :tunez, extensions: [AshJsonApi.Domain]

json_api do
routes do
base_route "/users", Tunez.Accounts.User do
post :register_with_password do
route "/register"

metadata fn _subject, user, _request ->
%{token: user.__metadata__.token}
end
end

post :sign_in_with_password do
route "/sign-in"

metadata fn _subject, user, _request ->
%{token: user.__metadata__.token}
end
end
end
end
end

resources do
resource Tunez.Accounts.Token
resource Tunez.Accounts.User
end
end
Shaba
ShabaOP4mo ago
Same with graphql
No description
No description
Shaba
ShabaOP4mo ago
I have confirmed the account after registering the users in both cases
barnabasj
barnabasj4mo ago
can you post your policy block from the user resource
Shaba
ShabaOP4mo ago
I found a typo
policy action([:register_with_password, :sigin_in_with_password]) do
authorize_if always()
end
policy action([:register_with_password, :sigin_in_with_password]) do
authorize_if always()
end
sigin_in_with_password should be sign_in_with_password Thank you!
Shaba
ShabaOP4mo ago
No description

Did you find this page helpful?