You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Calling Firebase validatePassword outside of an Injection context #3614
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';importtype{PasswordValidationStatus}from'@angular/fire/auth';importtype{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. */exportconstpasswordFirebaseValidator=(): AsyncValidatorFn=>{constauth: Auth=inject(Auth);constenvironmentInjector=inject(EnvironmentInjector);returnasync(control: AbstractControl<unknown>): Promise<ValidationErrors|null>=>{constvalue=getPasswordControlValue(control);// Like Validators.email, rely on Validators.required to check for blank passwords.if(value==undefined){returnnull;// eslint-disable-line unicorn/no-null -- ValidatorFn returns null}const{passwordPolicy: _, ...status}=awaitrunInInjectionContext(environmentInjector,async(): Promise<PasswordValidationStatus>=>validatePassword(auth,value),);returnstatus.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.
I'll look into reducing the log verbosity of the validate method, it shouldn't be necessary to be in an injection context for every single API but AngularFire can't guarantee stability without it.
I'm trying to create a demonstration app illustrating Angular, Firebase, and best practices. And I am running into this warning a bunch. So is there a better way to do things like this that I am missing?
For example the signOut modular method. I'm doing something quite similar to what is shown in this repo. And getting this same warning. So if there is a better way, I would love to use it now before I implement everything wrongly.
Activity
google-oss-bot commentedon Jan 22, 2025
This issue does not seem to follow the issue template. Make sure you provide all the required information.
jamesdaniels commentedon Jan 22, 2025
I'll look into reducing the log verbosity of the validate method, it shouldn't be necessary to be in an injection context for every single API but AngularFire can't guarantee stability without it.
rgant commentedon Jan 22, 2025
I'm trying to create a demonstration app illustrating Angular, Firebase, and best practices. And I am running into this warning a bunch. So is there a better way to do things like this that I am missing?
For example the
signOutmodular method. I'm doing something quite similar to what is shown in this repo. And getting this same warning. So if there is a better way, I would love to use it now before I implement everything wrongly.