{@thread.name}
talha-azeem:
Why does this screen comes up instead of displaying an error message that the credentials are not right.
ZachDaniel:
🤔 Is your form set up to submit the action?
ZachDaniel:
set up to submit the action over a controller route, I mean
ZachDaniel:
At the moment, the behavior is to submit over HTTP to log you in, which means that you’d need to, in your AuthController, redirect on failure
ZachDaniel:
This is what
ash_hq
does
def failure(
conn,
{:password, :sign_in},
%AshAuthentication.Errors.AuthenticationFailed{}
) do
conn
|> put_flash(
:error,
"Username or password is incorrect"
)
|> redirect(to: "/sign-in")
end
def failure(conn, activity, reason) do
stacktrace =
case reason do
%{stacktrace: %{stacktrace: stacktrace}} -> stacktrace
_ -> nil
end
Logger.error("""
Something went wrong in authentication
activity: #{inspect(activity)}
reason: #{Exception.format(:error, reason, stacktrace || [])}
""")
conn
|> put_flash(
:error,
"Something went wrong"
)
|> redirect(to: "/sign-in")
end
talha-azeem:
<.simple_form
:let={form}
id="login_form"
for={@form}
action={
route_helpers(@socket).auth_path(
@socket.endpoint,
{@subject_name, :password, :sign_in}
)
}
method="post"
phx-submit="save"
phx-trigger-action={@trigger_action}
phx-change="validate"
>
these are the current settings of the login form
talha-azeem:
now it redirects to the same page but doesn’t show the error message 😅
ZachDaniel:
So you need to add some code to your page/layout to render flash messages
ZachDaniel:
There is a guide for that in phoenix/phoenix liveview I’m sure 🙂
talha-azeem:
Yeah i know. I already have the flash messages setup
talha-azeem:
Thanks
ZachDaniel:
🤔 so its not showing the flash messages you’re setting?
talha-azeem:
It started working itself now.
talha-azeem:
Thank you <@197905764424089601> ❤️
ZachDaniel:
👍
talha-azeem:
<@197905764424089601> can you tell me one thing?
talha-azeem:
I was looking into the auth forms and there is one
reset_form
as well.
talha-azeem:
but there is not link or route to access that
ZachDaniel:
Correct, it switches not on a route
ZachDaniel:
It does it using liveview state
ZachDaniel:
there is a discussion about that here: https://discord.com/channels/711271361523351632/1068488089514811432
ZachDaniel:
If you want to do it with a separate route you can 🙂
talha-azeem:
reset password?
ZachDaniel:
Yeah, works the same way
ZachDaniel:
You can serve it over a different route if you want, just make another liveview for it
talha-azeem:
I thought that reset_form is for resetting the password
ZachDaniel:
yes, it is
ZachDaniel:
Its for requesting a forgotten password
talha-azeem:
then how can i access it? 😅
ZachDaniel:
like requesting an email with a password reset link
ZachDaniel:
You’re writing your own liveview…
ZachDaniel:
So you can access it however you want. I’m not sure I understand.
talha-azeem:
yes i used my own liveviews for registeration and login
ZachDaniel:
You’ll need to write your own liveview for password reset too
talha-azeem:
My concern was what strategy is being used there
talha-azeem:
like i can access the default sign-in page through
localhost:4000/sign-in
. I was wondering if there is any way to access that one as well
ZachDaniel:
There is no route for password reset currently. I think that will change because of issues like the one I linked where people want to link directly to those pages
ZachDaniel:
but for now, you can’t link to something like
/forgot-password
ZachDaniel:
Because it doesn’t have its own route
ZachDaniel:
But thats with the default built in stuff
ZachDaniel:
if you’re writing your own liveview, you can do <a:magic_sparkles:989799235274817646> whatever you want
talha-azeem:
Noted. Can you tell me what strategy is being used there? 😅
talha-azeem:
so i can implement that in my own liveviews?
ZachDaniel:
What do you mean what strategy?
talha-azeem:
like sign-in page have this strategy:
%AshAuthentication.Strategy.Password{
identity_field: :email,
hashed_password_field: :hashed_password,
hash_provider: AshAuthentication.BcryptProvider,
confirmation_required?: true,
password_field: :password,
password_confirmation_field: :password_confirmation,
register_action_name: :register_with_password,
sign_in_action_name: :sign_in_with_password,
resettable: [],
name: :password,
provider: :password,
resource: DataDrivenMicroscopy.Accounts.User
}
ZachDaniel:
Thats the same strategy
ZachDaniel:
I mean: that is the strategy for all of the forms around passwords
ZachDaniel:
I didn’t realize you meant the actual
AshAuthentication.Strategy
ZachDaniel:
Have you configured your strategy to be
resettable
?
talha-azeem:
but here the
resettable
is empty list
talha-azeem:
no? 😅
talha-azeem:
how can i do that?
ZachDaniel:
password :password do
identity_field :email
hashed_password_field :hashed_password
resettable do
sender AshHq.Accounts.User.Senders.SendPasswordResetEmail
end
end
ZachDaniel:
thats what I have in
ash_hq
ZachDaniel:
Take a look at the docs and search for resettable
talha-azeem:
i did search and found nothing
Ash HQ Bot:
Found 2 DSL results in ash_authentication:
frankdugan3:
Ooh, that’s a cool command! 😄
ZachDaniel:
🙂 I need to make a private version of it so it will respond not to everyone in the chat
talha-azeem:
I was about to say that <@433654314175692800>
ZachDaniel:
We’re going to be making the DSL docs much better soon
ZachDaniel:
but anyway, you can configure it the way I’ve shown
talha-azeem:
AshHq.Accounts.User.Senders.SendPasswordResetEmail
This is another module using swoosh or something to send email?
ZachDaniel:
ZachDaniel:
You can see all of the source code of ash_hq there
ZachDaniel:
So you can take a look at it and see what it does 🙂
talha-azeem:
Noted with Thanks