Json API for `request_password_reset_token` auth

Hi, sorry; I'm trying to create an endpoint for request_password_reset_token so that the user can send a password reset request. But the issue I'm facing seems to be that the structure isn't compatible with what the JSON API expects, and as a result, it throws an error. I wanted to know if there's a way to do this at this stage without changing the action itself?
post :request_password_reset_token do
route "/reset_request"
end
post :request_password_reset_token do
route "/reset_request"
end
I saw the wrap_in_result? option in the documentation, but I haven't been able to use it correctly I was wondering if that might solve the problem. Error:
[error] Process #PID<0.23241.0> raised an exception
** (Spark.Error.DslError) [MishkaCms.Accounts]
json_api -> routes -> post -> request_password_reset_token:
Invalid return type for generic action used in post route.

Expected type `:struct`
Expected constraints: instance_of: MishkaCms.Accounts.User

Got type: nil
Got constraints: []
[error] Process #PID<0.23241.0> raised an exception
** (Spark.Error.DslError) [MishkaCms.Accounts]
json_api -> routes -> post -> request_password_reset_token:
Invalid return type for generic action used in post route.

Expected type `:struct`
Expected constraints: instance_of: MishkaCms.Accounts.User

Got type: nil
Got constraints: []
By the way is there any source of implementing auth for graphql and json token? unfortunately the reset password dose not exist in https://github.com/seanchatmangpt/tunez/blob/chapter-7/lib/tunez/accounts.ex for example, i was force to implement my multi tendency and use master email and assigned a website email
post :sign_in_with_password do
route "/sign_in"

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
change the sign_in_with_password to
read :sign_in_with_password do
...

prepare fn query, _context ->
query = Ash.Query.set_context(query, %{private: %{ash_authentication?: true}})
current_tenant = query.tenant

if current_tenant,
do: Ash.Query.filter(query, site_id == ^current_tenant),
else: Ash.Query.filter(query, is_nil(site_id))
end

# validates the provided email and password and generates a token
prepare AshAuthentication.Strategy.Password.SignInPreparation

...
end
read :sign_in_with_password do
...

prepare fn query, _context ->
query = Ash.Query.set_context(query, %{private: %{ash_authentication?: true}})
current_tenant = query.tenant

if current_tenant,
do: Ash.Query.filter(query, site_id == ^current_tenant),
else: Ash.Query.filter(query, is_nil(site_id))
end

# validates the provided email and password and generates a token
prepare AshAuthentication.Strategy.Password.SignInPreparation

...
end
Thank you in advance
Solution:
So you need to use route ...
Jump to solution
3 Replies
ZachDaniel
ZachDaniel•2mo ago
request_password_reset_token does not return anything Use the route builder to create that route instead of post post expects to work against something that follows the standard JSON:API structure, but :request_password_reset_token is a generic action that doesn't return anything
Solution
ZachDaniel
ZachDaniel•2mo ago
So you need to use route ...
Shahryar
ShahryarOP•2mo ago
🥲 🥲 , after hours and wrong ai suggestions i found it https://hexdocs.pm/ash_json_api/dsl-ashjsonapi-domain.html#examples-14 I really need some sources with ash :)) to see the code 😂

Did you find this page helpful?