Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

Calling Firebase `validatePassword` outside of an Injection context

Đang mở
#3,614 3 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
42/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
angular, firebase, typescript
Lĩnh vực
authentication

Hướng nghiên cứu

Bắt đầu từ điểm vào validatePassword và wrapper runInInjectionContext được hiển thị, sau đó theo dõi cách AngularFire xử lý instance Auth và injection context. Xác định xem cảnh báo có phải là điều được mong đợi hay không và wrapper có bắt buộc hay không; hoàn thành khi đã ghi lại pattern gọi đúng hoặc đơn giản hóa việc validation mà không có cảnh báo.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Is the running outside of injection context warning legitimate when using validatePassword?

My code:

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<unknown>): Promise<ValidationErrors | null> => {
    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<PasswordValidationStatus> => 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.

Ngôn ngữ chính
TypeScript
Star
7.8k
Fork
2.2k
Merge trung bình
3 ngày 6 giờ
Pull request đã merge (30 ngày)
5

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của angular/angularfire

Tất cả issue của angular/angularfire

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.