Skip to content

Commit

Permalink
docs: Update docs to account for unconfirmed users (#775)
Browse files Browse the repository at this point in the history
Ensure oauth users cannot login with unconfirmed account #443
  • Loading branch information
dan-klasson authored Sep 1, 2024
1 parent ad29a2a commit baade96
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
11 changes: 11 additions & 0 deletions documentation/tutorials/github.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
11 changes: 11 additions & 0 deletions documentation/tutorials/google.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down

0 comments on commit baade96

Please sign in to comment.