✅ ASP.NET Core form with two submit buttons
I have a form
The problem with this code is next:
1. I'm trying to log in, login requires sms code. The application sends me a code
2. I click "Send code again", and application generates a new code and sends it to me
3. I enter the second code and click Verify button, but the application calls ResendCode handler and sends me a new code again.
Any idea why it can happen?
1 Reply
I also have a script on this page
The script itself
The interesting thing that this issue appears only in Chrome and Edge.
And looks like OPTCredential works only in chrome browsers https://caniuse.com/mdn-api_otpcredential.
But, commenting this code did not fix the issue
Ok, so I found a problem.
It's because, after the first call, the URL changes and contains now ?handler=ResendCode
The second button has only submit type, without any handlers.
I have a hunch that because of that, we are getting into the ResendCode handler all the time.
So I added a new handler for this button and from a new handler I return OnPostAsync.
After that everything works as expected. But I'm not sure if this is a good approach.
Any ideas if I can do it better?