Authentication Providers
Learn how to manage sessions, events, and different authentication options
OwnID Elite provides a powerful and flexible framework for integrating and customizing authentication processes within your applications. By leveraging Providers
and Events
, developers can implement or override specific aspects of the authentication flow, tailoring the user experience to meet the unique needs of their applications.
- Providers: These manage critical components such as session handling and authentication mechanisms, including traditional password-based sign-ins. They allow developers to define how users are authenticated, how sessions are maintained, and how accounts are managed within the application.
- Events: These handle specific actions and responses within the authentication flow. They allow developers to customize behaviors when certain events occur, such as when the authentication process finishes, when an error is encountered, or when the flow detects a new user and prompts for registration.
Providers
Session
The Session Provider is responsible for creating and managing user sessions. In this implementation, use the create
method to create a user session utilizing the data.token
returned from your backend, and return a status indicating whether the session creation was successful or not.
Authentication
The Auth Provider manages authentication mechanisms, such as password authentication. In this example, the authenticate
method validates the user’s credentials, and the reset
method handles password reset requests.
Explanation
authenticate
: This method attempts to log in the user using the provided loginId and password. If successful, it returns status: ‘logged-in’. If authentication fails, it returns status: ‘fail’ with a reason such as “Please enter a valid password.”reset
: This method handles the reset of user passwords. In this example, it redirects the user to a specific URL where they can manage password recovery.
Events
onFinish
The onFinish
event is triggered when the authentication flow is successfully completed. This event allows you to define actions that should be taken once the user is authenticated, such as redirecting the user to a specific page.
onAccountNotFound
onAccountNotFound
to use your own registration flowsThe onAccountNotFound
event is triggered when the provided account details do not match any existing accounts. This event allows you to handle scenarios where a user needs to be registered or redirected to a registration page.
onClose
The onClose
event is triggered when the authentication flow is closed, either by user action or automatically. This event allows developers to define what should happen when the authentication flow is interrupted or completed without a successful login.
onError
The onError
event is triggered when an error occurs during the authentication flow. This event allows developers to handle errors gracefully, such as by logging them or displaying error messages to the user.
Complete Code Example
Next Step
UI Customizations
Click here to move to the next step ->
Was this page helpful?