mirror of
https://github.com/team-alembic/ash_authentication.git
synced 2024-09-19 12:52:55 +12:00
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:
parent
ad29a2a9ff
commit
baade967ae
2 changed files with 22 additions and 0 deletions
|
@ -106,6 +106,7 @@ The register action takes two arguments, `user_info` and the `oauth_tokens`.
|
||||||
|
|
||||||
```elixir
|
```elixir
|
||||||
defmodule MyApp.Accounts.User do
|
defmodule MyApp.Accounts.User do
|
||||||
|
require Ash.Resource.Change.Builtins
|
||||||
use Ash.Resource,
|
use Ash.Resource,
|
||||||
extensions: [AshAuthentication],
|
extensions: [AshAuthentication],
|
||||||
domain: MyApp.Accounts
|
domain: MyApp.Accounts
|
||||||
|
@ -130,6 +131,16 @@ defmodule MyApp.Accounts.User do
|
||||||
|
|
||||||
Ash.Changeset.change_attributes(changeset, Map.take(user_info, ["email"]))
|
Ash.Changeset.change_attributes(changeset, Map.take(user_info, ["email"]))
|
||||||
end
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -38,6 +38,7 @@ Then we need to define an action that will handle the oauth2 flow, for the googl
|
||||||
|
|
||||||
```elixir
|
```elixir
|
||||||
defmodule MyApp.Accounts.User do
|
defmodule MyApp.Accounts.User do
|
||||||
|
require Ash.Resource.Change.Builtins
|
||||||
use Ash.Resource,
|
use Ash.Resource,
|
||||||
extensions: [AshAuthentication],
|
extensions: [AshAuthentication],
|
||||||
domain: MyApp.Accounts
|
domain: MyApp.Accounts
|
||||||
|
@ -60,6 +61,16 @@ defmodule MyApp.Accounts.User do
|
||||||
|
|
||||||
Ash.Changeset.change_attributes(changeset, Map.take(user_info, ["email"]))
|
Ash.Changeset.change_attributes(changeset, Map.take(user_info, ["email"]))
|
||||||
end
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue