docs: Update docs to account for unconfirmed users (#775)

Ensure oauth users cannot login with unconfirmed account https://github.com/team-alembic/ash_authentication/issues/443
This commit is contained in:
dan-klasson 2024-09-02 04:58:52 +08:00 committed by GitHub
parent ad29a2a9ff
commit baade967ae
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 22 additions and 0 deletions

View file

@ -106,6 +106,7 @@ The register action takes two arguments, `user_info` and the `oauth_tokens`.
```elixir
defmodule MyApp.Accounts.User do
require Ash.Resource.Change.Builtins
use Ash.Resource,
extensions: [AshAuthentication],
domain: MyApp.Accounts
@ -130,6 +131,16 @@ defmodule MyApp.Accounts.User do
Ash.Changeset.change_attributes(changeset, Map.take(user_info, ["email"]))
end
# Required if you're using the password & confirmation strategies
upsert_fields []
change set_attribute(:confirmed_at, &DateTime.utc_now/0)
change after_action(fn _changeset, user, _context ->
case user.confirmed_at do
nil -> {:error, "Unconfirmed user exists already"}
_ -> {:ok, user}
end
end)
end
end

View file

@ -38,6 +38,7 @@ Then we need to define an action that will handle the oauth2 flow, for the googl
```elixir
defmodule MyApp.Accounts.User do
require Ash.Resource.Change.Builtins
use Ash.Resource,
extensions: [AshAuthentication],
domain: MyApp.Accounts
@ -60,6 +61,16 @@ defmodule MyApp.Accounts.User do
Ash.Changeset.change_attributes(changeset, Map.take(user_info, ["email"]))
end
# Required if you're using the password & confirmation strategies
upsert_fields []
change set_attribute(:confirmed_at, &DateTime.utc_now/0)
change after_action(fn _changeset, user, _context ->
case user.confirmed_at do
nil -> {:error, "Unconfirmed user exists already"}
_ -> {:ok, user}
end
end)
end
end