Skip to content

Commit

Permalink
Upgrade deps, fix wrong nesting of authentication block (#147)
Browse files Browse the repository at this point in the history
  • Loading branch information
skanderm authored Jul 12, 2023
1 parent 4b0d09c commit 61c72e6
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 47 deletions.
66 changes: 33 additions & 33 deletions server/lib/orcasite/notifications/resources/subscription.ex
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
defmodule Orcasite.Notifications.Subscription do
use Ash.Resource,
extensions: [AshAdmin.Resource, AshAuthentication],
extensions: [AshAuthentication, AshAdmin.Resource],
data_layer: AshPostgres.DataLayer

alias Orcasite.Notifications.{Event, Notification, NotificationInstance, Subscriber}
Expand All @@ -17,6 +17,38 @@ defmodule Orcasite.Notifications.Subscription do
identity :id, [:id]
end

authentication do
api Orcasite.Notifications

strategies do
magic_link :unsubscribe do
identity_field :id

single_use_token? false
# 14 days (in minutes)
token_lifetime 1_209_600

sender fn subscription, token, _opts ->
IO.inspect({subscription, token},
label:
"{subscription, token} (server/lib/orcasite/notifications/resources/subscription.ex:#{__ENV__.line})"
)

# Orcasite.Emails.deliver_magic_link(user, token)
end
end
end

tokens do
enabled? true
token_resource Orcasite.Notifications.Token

signing_secret fn _, _ ->
{:ok, Application.get_env(:orcasite, OrcasiteWeb.Endpoint)[:secret_key_base]}
end
end
end

actions do
defaults [:create, :read, :update, :destroy]

Expand Down Expand Up @@ -47,38 +79,6 @@ defmodule Orcasite.Notifications.Subscription do
change manage_relationship(:subscriber, type: :append)
end

authentication do
api Orcasite.Notifications

strategies do
magic_link :unsubscribe do
identity_field :id

single_use_token? false
# 14 days (in minutes)
token_lifetime 1_209_600

sender fn subscription, token, _opts ->
IO.inspect({subscription, token},
label:
"{subscription, token} (server/lib/orcasite/notifications/resources/subscription.ex:#{__ENV__.line})"
)

# Orcasite.Emails.deliver_magic_link(user, token)
end
end
end

tokens do
enabled? true
token_resource Orcasite.Notifications.Token

signing_secret fn _, _ ->
{:ok, Application.get_env(:orcasite, OrcasiteWeb.Endpoint)[:secret_key_base]}
end
end
end

update :update_last_notification do
accept [:last_notification]

Expand Down
Loading

0 comments on commit 61c72e6

Please sign in to comment.