Skip to content

Conversation

ankita10119
Copy link
Contributor

@ankita10119 ankita10119 commented Aug 21, 2025

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:

  • Signup
  • Signup-password
  • signup-id
  • Login

References

Include any links supporting this change such as a:

  • GitHub Issue/PR number addressed or fixed
  • Auth0 Community post
  • StackOverflow post
  • Support forum thread
  • Related pull requests/issues from other repos

If there are no references, simply delete this section.

Testing

Tested and validated these changes with sample react app via universal-login-samples screen examples.

  • This change adds test coverage for new/changed/fixed functionality

Checklist

  • I have added documentation for new/changed functionality in this PR or in auth0.com/docs
  • All active GitHub checks for tests, formatting, and security are passing
  • The correct base branch is being used, if not the default branch

@ankita10119 ankita10119 requested a review from a team as a code owner August 21, 2025 19:52
* 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;
Copy link
Contributor

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;
Copy link
Contributor

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.

allowedIdentifiers

requiredIdentifiers

The current implementation covers only username-password flow.

*/
function getIdentifier(): Identifier[] {
const context = new BaseContext();
const transactionContext = context.getContext('transaction');
Copy link
Contributor

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(
Copy link
Contributor

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.

@ankita10119 ankita10119 changed the title feat: introduce usePasswordValidation and useIdentifiers utility hooks feat: Introduce validatePassword, getIdentifiers and getActiveIdentifiers helper methods Aug 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants