Okta Sign-In WIdget login failed event handler

Hi,

I am trying to capture and log the event when user login has failed, I’m thinking about an ajax call to my logging API. Is there an event handler in the okta javascript configuration where I can insert my code and capture the failed login attempt?

Looking forward to any advice.

Best,
Jed

1 Like

Hi @cayetanojed,

The Widget render function either results in a success or error. The error function is called when the Widget has been initialized with invalid config options, or has entered a state it cannot recover from.
You can do something like this:

 // No session, show the login form
            oktaSignIn.renderEl(
                { el: '#okta-login-container' },
                function success(res) {
                    // Nothing to do in this case, the widget will automatically redirect
                    // the user to Okta for authentication, then back to this page if successful
                },
                function error(err) {
                    // handle errors as needed
                    console.error(err);
                }
            );

Take a look at these resources:

1 Like

@cayetanojed As Laura mentioned, the error handler you pass to the widget is used to catch unhandled errors. The widget doesn’t currently provide a way to hook into “non-fatal” errors like a bad user login. We are investigating adding new events to the widget to make this possible.

I’ll post back in this thread when we add this feature. Stay tuned!

Hello,

Thank you for the quick replies. It’s sad that it is not supported yet, so I went for another solution which was to observe some DOM mutation using JavaScript, specifically for the appearance of the okta error box saying that the user name and/or password is invalid, then call my logging API thereafter. I don’t really think this is the most elegant solution for this, but it does the job for now. If you have a better suggestion in mind, please feel free to post a reply in this thread. I’ll look forward for the addition of this feature.

Thanks,

Jed

Hello cayetanojed,

We are trying to do the same thing only if the problem is that the user hasn’t activated their account.
What code did you use to detect the DOM mutation? What event are you using to call your code?

We’re hoping to display a modal that will allow the user to self-activate if they failed to login due to STAGED status. We’re planning on sending users activation emails, but they expire and want to make sure they can activate at any time.

Thanks,
Dana

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.