-
Notifications
You must be signed in to change notification settings - Fork 5
feat: Introduce validatePassword, getIdentifiers and getActiveIdentifiers helper methods #155
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: auth0-acul-react
Are you sure you want to change the base?
Conversation
…re for validatePassword utility hook
* Type guard to ensure connection is of type DBConnection. | ||
*/ | ||
function isDBConnection(conn: unknown): conn is DBConnection { | ||
return typeof conn === 'object' && conn !== null && 'options' in conn; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would return true
for PasswordlessConnection
as-well.
} | ||
} | ||
|
||
return activeIdentifiers; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have the following implementation which would work for password-less
flow as well.
The current implementation covers only username-password flow.
*/ | ||
function getIdentifier(): Identifier[] { | ||
const context = new BaseContext(); | ||
const transactionContext = context.getContext('transaction'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we using getContext
here ?
Can't we implement it similar to validatePassword
?
import type { PasswordValidationResult } from '../../interfaces/models/screen'; | ||
import type { PasswordPolicy, Error, PasswordComplexityRule } from '../../interfaces/models/transaction'; | ||
|
||
function validatePassword( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unit test is missing for this implementation.
Description
This PR introduces two new utility hooks to support reusable logic in form validation and identifier handling across screens:
🔧 Changes Introduced:
usePasswordValidation:
Validates password input against the current passwordPolicy from context.
Helps prevent network requests when client-side password validation fails.
useIdentifiers:
Provides a unified list of required and optional identifiers (email, phone, username) based on the current transaction context.
Enables dynamic rendering of identifier fields in forms.
useActiveIdentifiers:
Provides a list of identifiers the user can use for sign-in. This hook can be used in login-id and login screens.
Enables dynamic rendering of identifier fields in forms.
🎯 Purpose:
Centralizes password validation logic to ensure consistency across screens.
Improves form rendering flexibility based on identifier configuration.
Avoids direct use of transaction.errors for pre-submit validations.
🧪 Screens Affected:
References
Testing
Tested and validated these changes with sample react app via universal-login-samples screen examples.
Checklist