implementing custom register form

I was looking into the register_form.ex and found a key @strategy. What is it used for?
31 Replies
ZachDaniel
ZachDaniel•3y ago
The strategy is the configuration for which authentication strategy is being used. You likely don't need it yourself You may need to use it when calling certain actions/changes
talha-azeem
talha-azeemOP•3y ago
I am observing the register_form.ex and trying to change my registration live view like that. strategy resource was getting used in get_params/2 i changed this function to get_params/1 and provided the resource manually. is this approach okay?
ZachDaniel
ZachDaniel•3y ago
I'm honestly not intimately familiar with that part of the code, but I'm sure its fine. Since the code is generic, you'll probably end up replacing a lot of parts that reference something like strategy.resource with your own resource So the only thing you need that it doesn't do right now is additional fields on register?
talha-azeem
talha-azeemOP•3y ago
yes
ZachDaniel
ZachDaniel•3y ago
We can add that feature to ash_authentication_phoenix, if you can wait for it šŸ™‚ and then you don't need to do all that work
talha-azeem
talha-azeemOP•3y ago
@Zach Daniel I will appreciate that. It will be a good feature to have. I am afraid I can't wait tho. I have a deadline to meet. šŸ˜… I am having one difference from the original registration form at the moment that if my password is not upto the mark then it empties the whole form and says fields are required.
ZachDaniel
ZachDaniel•3y ago
Hard to say whats wrong with that without seeing the implementation.
talha-azeem
talha-azeemOP•3y ago
fixed it šŸ˜„ I am getting the hang of it Thanks to you @Zach Daniel šŸ™Œ I really appreciate that you are helping me out. just a single issue šŸ˜… I am not getting the password confirmation field
ZachDaniel
ZachDaniel•3y ago
what do you mean by not getting?
talha-azeem
talha-azeemOP•3y ago
like it is not getting rendered on the page.
ZachDaniel
ZachDaniel•3y ago
What does it look like? The code, I mean
talha-azeem
talha-azeemOP•3y ago
my bad. I didn't include it in the form šŸ˜… šŸ˜‚ @Zach Daniel How do we handle timestamps in ASH? like normally they get entered automatically.
ZachDaniel
ZachDaniel•3y ago
attributes do
timestamps()
end
attributes do
timestamps()
end
talha-azeem
talha-azeemOP•3y ago
yeah i added that
ZachDaniel
ZachDaniel•3y ago
That will add the timestamps automatically on create/update, is that not what you mean?
talha-azeem
talha-azeemOP•3y ago
** (Postgrex.Error) ERROR 42703 (undefined_column) column "created_at" of relation "tokens" does not exist

query: INSERT INTO "tokens" AS t0 ("created_at","expires_at","jti","purpose","subject","updated_at") VALUES ($1,$2,$3,$4,$5,$6) ON CONFLICT ("jti") DO UPDATE SET "updated_at" = $7, "expires_at" = $8, "jti" = $9, "purpose" = $10, "subject" = $11 RETURNING "jti","subject","expires_at","purpose","extra_data","created_at","updated_at"
** (Postgrex.Error) ERROR 42703 (undefined_column) column "created_at" of relation "tokens" does not exist

query: INSERT INTO "tokens" AS t0 ("created_at","expires_at","jti","purpose","subject","updated_at") VALUES ($1,$2,$3,$4,$5,$6) ON CONFLICT ("jti") DO UPDATE SET "updated_at" = $7, "expires_at" = $8, "jti" = $9, "purpose" = $10, "subject" = $11 RETURNING "jti","subject","expires_at","purpose","extra_data","created_at","updated_at"
got this.
ZachDaniel
ZachDaniel•3y ago
You need to generate migrations
talha-azeem
talha-azeemOP•3y ago
while registration yeah i already did that migrated it as well
ZachDaniel
ZachDaniel•3y ago
Do you have the accounts api in config :your_app, ash_apis: [...]?
talha-azeem
talha-azeemOP•3y ago
oh, the db have the column inserted_at
No description
talha-azeem
talha-azeemOP•3y ago
yes
ZachDaniel
ZachDaniel•3y ago
How did you get it to look for :created_at?
talha-azeem
talha-azeemOP•3y ago
that i don't know myself šŸ˜…
ZachDaniel
ZachDaniel•3y ago
Are you sure thats code coming from Ash? is there a stacktrace?
ZachDaniel
ZachDaniel•3y ago
Can I see your tokens resource?
talha-azeem
talha-azeemOP•3y ago
defmodule Dummy.Accounts.Token do
use Ash.Resource,
data_layer: AshPostgres.DataLayer,
extensions: [AshAuthentication.TokenResource]

token do
api Dummy.Accounts
end

postgres do
table "tokens"
repo Dummy.Repo
end
end
defmodule Dummy.Accounts.Token do
use Ash.Resource,
data_layer: AshPostgres.DataLayer,
extensions: [AshAuthentication.TokenResource]

token do
api Dummy.Accounts
end

postgres do
table "tokens"
repo Dummy.Repo
end
end
Something was wrong with the DB i guess. I dropped it. Recreated and migrated It works now
ZachDaniel
ZachDaniel•3y ago
šŸ‘ FWIW if you want timestamps on the tokens you'll need to add it
talha-azeem
talha-azeemOP•3y ago
tokens table have them by default
ZachDaniel
ZachDaniel•3y ago
oh, okay šŸ‘
talha-azeem
talha-azeemOP•3y ago
Closing this thread and opening a new one

Did you find this page helpful?