Error: HomeComponent was not able to properly inject null values

Encountering an error upon starting the HomeComponent. The configuration set in the environment file is correct. Is there a possibility of incorrect injection? Do I need to inject additional items? Provided are the files being utilized. Assistance would be greatly appreciated, thank you

Error:
ERROR Error [NullInjectorError]: R3InjectorError(Standalone[_HomeComponent])[_AuthenticationService -> _AuthenticationService -> _AngularFireAuth -> InjectionToken angularfire2.app.options -> InjectionToken angularfire2.app.options]

app.config.ts

export const appConfig: ApplicationConfig = {
      providers: [
        provideZoneChangeDetection({ eventCoalescing: true }),
        provideRouter(routes),
        provideClientHydration(),
        provideHttpClient(withFetch()),

    provideFirebaseApp(() => initializeApp(environment.firebaseConfig)),
    provideAuth(() => getAuth()),
    provideFirestore(() => getFirestore()),
  ]
};

home.component.ts

import { Component } from '@angular/core';
import { RouterLink } from '@angular/router';
import { TranslateModule } from '@ngx-translate/core';
import { AuthenticationService } from '../auth/authentication.service';

@Component({
  selector: 'app-home',
  standalone: true,
  imports: [TranslateModule, RouterLink],
  templateUrl: './home.component.html',
})
export class HomeComponent {

  constructor(private auth: AuthenticationService) { }

  signOut() {
    this.auth.signOut().subscribe({
      next: () => {
      },
      error: error => {
      }
    });
  }
}

authentication.service.ts

import { Injectable } from '@angular/core';
import { AngularFireAuth } from '@angular/fire/compat/auth';
import { FirebaseError } from 'firebase/app';
import { catchError, from, Observable, throwError } from 'rxjs';

@Injectable({
    providedIn: 'root'
})
export class AuthenticationService {

    constructor(private auth: AngularFireAuth) { }

    signIn(email: string, password: string): Observable<any>{
        return from(this.auth.signInWithEmailAndPassword(email, password))
        .pipe(
            catchError((error: FirebaseError) =>
                throwError(() => console.log('Error'))
            )
        );
    }

    signUp(email: string, password: string): Observable<any>{
        return from(this.auth.createUserWithEmailAndPassword(email, password)).pipe(
            catchError((error: FirebaseError) =>
                throwError(() => console.log('Error'))
            )
        );
    }

    //exc...
}

this is main.ts

import { bootstrapApplication } from '@angular/platform-browser';
import { appConfig } from './app/app.config';
import { AppComponent } from './app/app.component';

bootstrapApplication(AppComponent, appConfig)
  .catch((err) => console.error(err));

Answer №1

To utilize the Auth module from @angular/fire/auth, make sure to follow the documentation provided below. Your code snippet should look like this:

constructor(private auth: Auth) { }

Angular Fire - Authentication Docs

Angular Fire - Readme.md

import { Auth, authState } from '@angular/fire/auth';
...

export class UserComponent implements OnDestroy {
  private auth: Auth = inject(Auth); // <- notice!
  authState$ = authState(auth);
  authStateSubscription: Subscription;
  ...

  constructor() {
    this.authStateSubscription = this.authState$.subscribe((aUser: User | null) => {
        //handle auth state changes here. Note, that user will be null if there is no currently logged in user.
     console.log(aUser);
    })
  }

  ngOnDestroy() {
    // when manually subscribing to an observable remember to unsubscribe in ngOnDestroy
    this.authStateSubscription.unsubscribe();
  }
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Exploring the potential of integrating Imgur API with Angular4

I'm currently in the process of developing a web application using Angular, and I'm encountering difficulties with the Imgur API integration. My main objective is to create a form where users can select their photos, which will then be uploaded t ...

Uncovering the Image Orientation in Angular: Is it Possible to Determine the Direction Post-view or Upon Retrieval from Database?

I am currently working on creating centered and cropped thumbnails for images retrieved from a database. I came across some helpful information on how to achieve this: The resource I found is written for JavaScript, but I am using Angular 7. I am facing d ...

Webpack does not support d3-tip in its current configuration

I'm having some trouble getting d3-tip to work with webpack while using TypeScript. Whenever I try to trigger mouseover events, I get an error saying "Uncaught TypeError: Cannot read property 'target' of null". This issue arises because th ...

The Angular HTML component is failing to display the locally stored JSON data upon page initialization

import { Store,STORES } from '../models/store'; export class StoreLocatorComponent implements OnInit { public Stores: any = []; constructor() { } ngOnInit(): void { this.Stores = STORES ; this.Stores.forEach(element => { ...

Encountering errors in Typescript build due to issues in the node_modules directory

While running a typescript build, I encountered errors in the node_modules folder. Despite having it listed in the exclude section of my tsconfig.json file, the errors persist. What's puzzling is that another project with identical gulpfile.js, tsconf ...

Adjust the range to match the specified step increment

I have an array of numbers like this: const dataset = [0.5, 2, 1, 93, 67.5, 1, 7, 34]; The minimum value is 0.5 and the maximum value is 93. I want to round the extremes of this dataset to a specified step value. For example: If step = 5, the result sho ...

What would happen if I eliminated the preset test cases from a large-scale Angular project?

Currently, in my Angular 5 enterprise application, I have developed numerous components and services using the Angular CLI. Each of these components and services has spec files with the default test case 'Component/Service should be created'. Co ...

Error encountered during Angular CLI's production build: TypeError - Attempting to access property 'kind' of an undefined value

To view the error message, click here { "@angular-devkit/build-angular": "~0.803.19", "@angular/cli": "~8.3.19", "@angular/compiler-cli": "~8.2.14", "@angular/language-service": "~8.2.14", "@types/jasmine": "~3 ...

A Guide to Uploading Photos to Firebase Storage and Storing the Photo URL in Firestore

My primary objective for this module is to upload the user's profile picture to Firebase Storage and save the Photo URL in Firestore (Cloud Firestore). Note: The images I upload are only in JPG and PNG format. This is a Cross Platform Application de ...

The language service for Angular is not functioning properly within the VSCode environment

Angular Latest Version Information Package Version ----------------------------------------------------------- @angular-devkit/architect 0.13.6 @angular-devkit/build-angular 0.13.6 @angular-devkit/build-optimizer 0. ...

Retrieve a static property from a specific type

I've encountered a dilemma with the code snippet below: class Action { public static DEPENDENCIES: (typeof Action)[] = []; public static MIN_USES: number | null = null; public static MAX_USES: number | null = null; } class SomeAction ext ...

What are the specific purposes of utilizing semantic versioning (semver) notation within the package.json file?

Could someone clarify the specific distinctions between the semver notations found in package.json file? I'd appreciate a detailed explanation. ...

Generating mat-option elements using ngFor on an empty initialized list

How can I dynamically update the values in the "specialisation" mat-select when a skill is selected in the "competence" mat-select? I have tried using [(ngModel)] to link my variable with the model, but it doesn't seem to update the list. I attempted ...

Encountering a Installation Issue with Angular CLI on Ubuntu 20.04

When trying to install @angular/cli globally using the command sudo npm install -global @angular/cli, an error was encountered. The error message displayed warnings about deprecated libraries and an existing file that caused the installat ...

AADSTS70002: In order for the request to be processed, the request body must include one of the following parameters: 'client_secret' or 'client_assert

I have implemented the Azure Active Directory library for Cordova from this GitHub repository and here is a snippet of my code : document.addEventListener("deviceready", () => { let authContext = new Microsoft.ADAL.AuthenticationContext("https://login. ...

Is it possible to view Intersection types in Typescript as a subtype of the types included in the intersection?

I've been exploring the concepts of generic types and subtypes in TypeScript, but despite my efforts to delve into the official documentation, I'm still left with a lingering question. Specifically, I'm curious: Is an intersection type poten ...

Encountering error: Unknown flag '-p' when trying to execute yarn build:prod in Angular 6

For the past two days, I have been encountering a problem. After updating Angular from version 4 to 6, I am unable to generate a production build. Commands like yarn build and yarn dev are functioning properly. However, when I execute yarn build:prod, I re ...

The Never-Ending Vue Loop in Testing

I'm facing an issue where the following component gets stuck in an infinite re-render loop during testing, even though it works perfectly fine in the application. The component simply receives some data via an event bus, maps it to something usable in ...

Looking to send a POST request with a particular object type

Currently, I am working with an abstract class called "Achievement" which has two subclasses: "ExhibitsVisitedAchievement" and "RouteFinishedAchievement". My goal is to create instances of these achievements by using a POST call to the relevant API endpoin ...

What causes the undefined value of 'this' in the parent typescript class?

In my Deno Typescript project, I have the following class hierarchy: AccountPutController.ts export class AccountPutController extends HttpController { constructor(commandBus: CommandBus) { super(commandBus) } async handle({ params, ...