Calling Firebase `validatePassword` outside of an Injection context
- 主要语言
- TypeScript
- 星标
- 7.8k
- 派生
- 2.2k
- 平均合并
- 22 小时 28 分钟
- 30 天内合并 PR
- 6
描述
Is the running outside of injection context warning legitimate when using `validatePassword`?
My code:
```ts
import { EnvironmentInjector, inject, runInInjectionContext } from '@angular/core';
import { Auth, validatePassword } from '@angular/fire/auth';
import type { PasswordValidationStatus } from '@angular/fire/auth';
import type { AbstractControl, AsyncValidatorFn, ValidationErrors } from '@angular/forms';
import { getPasswordControlValue } from './util';
/**
* Validate against the Firebase Project Authentication Password Policy.
*
* Note: at this time there is no actual need for this because the policy only enforces length and
* other Validators already check for that. However it is nice to know how to do this.
*/
export const passwordFirebaseValidator = (): AsyncValidatorFn => {
const auth: Auth = inject(Auth);
const environmentInjector = inject(EnvironmentInjector);
return async (control: AbstractControl): Promise => {
const value = getPasswordControlValue(control);
// Like Validators.email, rely on Validators.required to check for blank passwords.
if (value == undefined) {
return null; // eslint-disable-line unicorn/no-null -- ValidatorFn returns null
}
const { passwordPolicy: _, ...status } = await runInInjectionContext(
environmentInjector,
async (): Promise => validatePassword(auth, value),
);
return status.isValid ? null : { firebasevalidator: status }; // eslint-disable-line unicorn/no-null
};
};
```
I added `EnvironmentInjector` and `runInInjectionContext` and that got rid of the warning, but is all this necessary? It would be nice if validation was simplier.
贡献指南
调研方向
从 validatePassword 入口点和所示的 runInInjectionContext 包装器开始,然后跟踪 AngularFire 如何处理 Auth 实例和注入上下文。确定该警告是否符合预期,以及是否需要这个包装器;完成标准是记录正确的调用模式,或在不产生警告的情况下简化验证。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- angular, firebase, typescript
- 领域
- authentication
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 42/100