sezaru
My user resource thas the following relationship:
many_to_many :schools, School do
through UserSchool
join_relationship :user_schools
source_attribute_on_join_resource :user_id
destination_attribute_on_join_resource :school_id
end
In my School resource, I have the following policy:
policies do
alias School.Checks
policy always() do
authorize_if Checks.IsConfirmed
end
end
And the IsConfirmed check is implemented as this:
defmodule Core.Ash.Checks.IsConfirmed do
@moduledoc false
use Ash.Policy.SimpleCheck
def describe(_), do: "actor account is confirmed"
def match?(%{confirmed_at: nil}, _, _), do: false
def match?(%{confirmed_at: _}, _, _), do: true
end
After upgrading to Ash 3.0, when I try to sign-in using the sign_in_with_password action, the actor field from match?/3 always arrive as nil which will fail the match of the check.
Did something changed that I need to update to make this work again? I check both Ash upgrade guide and Ash authentication one but didn’t find anything that would help.
Trending in Questions
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
Hello,
I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
So my question is quite simple and i have found no conclusive answer on forum, google or AI.
Should we use :erlang.float for Integer to ...
New
Documentation
While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New
Other Trending Topics
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself.
My main conc...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #ai
- #elixirconf-us
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
zachdaniel
Hm…the actor is never set when calling
sign_in_with_passwordAFAIK. It’s not set because we don’t know who it is yet, because the user isn’t authenticated. Are you saying this is happening in the:sign_in_with_passwordaction? Or is this perhaps happening elsewhere?Actually, I bet I know what changed
The default for
authorize?is nowtrue(see the upgrade guide for more on that). Eitherauthorize?: falsesezaru
Hmm, shouldn’t
authorize?be false when calling thesign_in_with_passwordaction since, as you correctly said, there is no actor?I could change it to false manually, but that would apply to every call the
School.readaction correctly?What I would prefer is to know if the parent action is a
ash_authenticationaction and handle that accordingly in my policy, but looking at the context, I couldn’t find anything that indicates that thesign_in_with_passwordaction was called.I also tried to add the ash_authentication
bypassrule toSchoolbut that doesn’t seem to work either.Any idea on how I can achieve this? Otherwise I think I will just have to create a
match?case where ifactorisnilit will authorize, but that doesn’t seem very secure.zachdaniel
authorize?will betruewhen callingsign_in_with_password. It’s not sufficient to know that a given action is an action added by ash authentication, because ash authentication isn’t the only thing capable of calling it.When you say “parent action”. Definitely don’t create a match allowing a non-logged in user to do the action you’re writing.
I think the missing context here is that you haven’t explained yet exactly what is being called and from where. It’s reasonable to hook into the actions you’re hooking into, but how are you doing it? What is triggering a read of
Schoolwhen a user signs in?sezaru
Ah, sorry if I was not clear.
The
School.readaction is being called by thismany_to_manyrelationship:So, basically, when I run the
sign_in_with_passwordaction, the:schoolrelationship will be loaded by default which will callSchool.readaction and will call myIsConfirmedcheck.zachdaniel
How are you accomplishing the loading by default? A global preparation?
sezaru
Yep, like this:
zachdaniel
Gotcha.
. Do you need those loaded on the registration action?
sezaru
So, I use these loads to handle next steps after an user signs-in (or register). For example, I will check the
subscriptionrelationship to see if there a plan already active. Or I will check if the school page I’m in right now is one that the user should have access (checking theschoolsrelationship), etc.i guess I could split this into a manual
Ash.loadfunction call after the user sign-in, but in that case I would need to be very careful to always add these whenever I’m updating the user.If that is the correct/better way to handle it, I will do it, but at the same time I was wondering if there is workarounds
zachdaniel
There are workarounds, yes
Something like this might do it?
sezaru
Shouldn’t
Ash.load(query, load_statement, actor: user)beAsh.load(user, load_statement, actor: user)andAsh.Query.load(query, load_statement)beAsh.Query.load(user, load_statement)?