angular / angular/angularfire

Calling Firebase `validatePassword` outside of an Injection context

オープン
#3,614 コメント 3 件 リアクション 0 件 担当者 0 名 GitHub で見る
主要言語
TypeScript
スター
7.8k
フォーク
2.2k
平均マージ
22時間 28分
マージ済み PR(30日)
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

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。