POW: Customize authetication based on subdomain

My application has multiple subdomains and I want to use the subdomain info to authenticate the user. I tried to create a custom context and change the get_by method to include the subdomain info in the clauses, but since I dont have the connection here I can access the subdomain. How can I access my conn.assigns from inside a custom context?

EDIT: Cleared the question up a bit.

You would pass in the subdomain information as function args to your authentication context function.

But how if the context is called by Pow?

I need that the SQL to get my user have and extra clause. The normal get_by method only queries for the email. I need it to check for the email AND the subdomain but by this example Pow.Ecto.Context — Pow v1.0.22 the context have no information from my connection whatsoever.

I created the custom context, but I don’t know how to make the subdomain info get here.

I’m not sure. Based on the number of people who have issues with using Pow when their use case is slightly different than “normal”, I am personally very concerned about Pow. I run into folks who can’t figure out how to use Pow with Absinthe, Pow with this sort of situation, basically Pow with anything other than a 100% vanilla Phoenix app. It is too much magic, and too little regular functions, and that makes it hard or impossible to do normal things.

Hey @danschultzer, is there a way to do this in pow?

One option that would be a bit hacky is to use the process dictionary:

# in your plug that looks at the subdomain
Process.put(:subdomain, subdomain)

# in your pow_context
subdomain = Process.get(:subdomain)

Using the process dictionary this way is considered a bit hacky since it’s bringing sort of a mutable variable approach to what is generally a functional language, but it might at least get you unblocked for the moment while you look for alternatives.

Oh thanks for the tip! I’ll try some other stuff and if all else fails I"ll go with it.