Ash FrameworkAF
Ash Frameworkโ€ข6mo agoโ€ข
7 replies
Shahryar

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


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: []


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

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


Thank you in advance
Solution
So you need to use route ...
Was this page helpful?