Skip to content

Commit f8b16f4

Browse files
committed
Add validatePassword method with implementation TODO
1 parent 173d9ca commit f8b16f4

File tree

3 files changed

+42
-2
lines changed

3 files changed

+42
-2
lines changed

packages/auth/src/core/auth/auth_impl.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ import {
3232
ErrorFn,
3333
NextFn,
3434
Unsubscribe,
35-
PasswordPolicy
35+
PasswordPolicy,
36+
PasswordValidationStatus
3637
} from '../../model/public_types';
3738
import {
3839
createSubscribe,
@@ -427,6 +428,11 @@ export class AuthImpl implements AuthInternal, _FirebaseService {
427428
}
428429
}
429430

431+
async validatePassword(password: string): Promise<PasswordValidationStatus> {
432+
// TODO(chazzy): Implement.
433+
return Promise.reject(password);
434+
}
435+
430436
_getPasswordPolicy(): PasswordPolicy | null {
431437
if (this.tenantId === null) {
432438
return this._projectPasswordPolicy;

packages/auth/src/core/index.ts

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ import {
2323
User,
2424
CompleteFn,
2525
ErrorFn,
26-
Unsubscribe
26+
Unsubscribe,
27+
PasswordValidationStatus
2728
} from '../model/public_types';
2829
import { _castAuth } from '../core/auth/auth_impl';
2930

@@ -96,6 +97,37 @@ export function initializeRecaptchaConfig(auth: Auth): Promise<void> {
9697
return authInternal.initializeRecaptchaConfig();
9798
}
9899

100+
/**
101+
* Validates the password against the password policy configured for the project or tenant.
102+
*
103+
* @remarks
104+
* If no tenant ID is set on the `Auth` instance, then this method will use the password
105+
* policy configured for the project. Otherwise, this method will use the policy configured
106+
* for the tenant. If a password policy has not been configured, then the default policy
107+
* configured for all projects will be used.
108+
*
109+
* If an auth flow fails because a submitted password does not meet the password policy
110+
* requirements and this method has previously been called, then this method will use the
111+
* most recent policy available when called again.
112+
*
113+
* @example
114+
* ```javascript
115+
* validatePassword(auth, 'some-password');
116+
* ```
117+
*
118+
* @param auth The {@link Auth} instance.
119+
* @param password The password to validate.
120+
*
121+
* @public
122+
*/
123+
export async function validatePassword(
124+
auth: Auth,
125+
password: string
126+
): Promise<PasswordValidationStatus> {
127+
const authInternal = _castAuth(auth);
128+
return authInternal.validatePassword(password);
129+
}
130+
99131
/**
100132
* Adds an observer for changes to the signed-in user's ID token.
101133
*

packages/auth/src/model/auth.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
Config,
2222
EmulatorConfig,
2323
PasswordPolicy,
24+
PasswordValidationStatus,
2425
PopupRedirectResolver,
2526
User
2627
} from './public_types';
@@ -103,4 +104,5 @@ export interface AuthInternal extends Auth {
103104
useDeviceLanguage(): void;
104105
signOut(): Promise<void>;
105106
initializeRecaptchaConfig(): Promise<void>;
107+
validatePassword(password: string): Promise<PasswordValidationStatus>;
106108
}

0 commit comments

Comments
 (0)