Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update documentation for HashPasswordChange #842

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions lib/ash_authentication/strategies/password/hash_password_change.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,22 @@ defmodule AshAuthentication.Strategy.Password.HashPasswordChange do

You can use this change in your actions where you want to change the user's
password. If you're not using one of the actions generated by the password
strategy then you'll need to manually pass the strategy name in the changeset
context. Eg:
strategy then you'll need to manually pass the changeset through the change
function. Eg:

```elixir
Changeset.new(user, %{})
|> Changeset.set_context(%{strategy_name: :password})
|> Changeset.for_update(:update, params)
|> Accounts.update()
Comment on lines -14 to -17
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right that Ash.Changeset.new/2 is gone, however the rest of your example is incorrect.

It should probably be more like:

Changeset.new(user)
|> Changeset.set_context(%{strategy_name: :password})
|> Changeset.for_update(:change_password, params)
|> Accounts.update()

Ash.Changeset.new(user)
|> Ash.Changeset.set_argument(:your_unencrypted_password_field, "new password")
|> AshAuthentication.Strategy.Password.HashPasswordChange([strategy: :password], [])
|> Ash.update()
```

or by adding it statically to your action definition:

```elixir
update :change_password do
argument :your_unencrypted_password_field, :string, sensitive?: true

change set_context(%{strategy_name: :password})
change AshAuthentication.Strategy.Password.HashPasswordChange
end
Expand All @@ -30,6 +32,8 @@ defmodule AshAuthentication.Strategy.Password.HashPasswordChange do

```elixir
update :change_password do
argument :your_unencrypted_password_field, :string, sensitive?: true

change {AshAuthentication.Strategy.Password.HashPasswordChange, strategy_name: :password}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that these examples should be updated to match the action that the add strategy igniter generates.

end
```
Expand Down