Oops! The 'map' property cannot be found in the type 'Observable<User>'

In my online shopping project that combines Angular and Firebase, I implemented the AuthGuard to verify user login status before accessing various links including ./check-out. However, I encountered an issue with importing map for Observable.User. All components are using the latest versions. auth.service.ts

import { Observable } from 'rxjs';
import { Injectable } from '@angular/core';
import { AngularFireAuth } from '@angular/fire/auth';
import * as firebase from 'firebase';

@Injectable({
  providedIn: 'root'
})
export class AuthService {
  user$: Observable<firebase.User>;

  constructor(private afAuth: AngularFireAuth) { 
    this.user$=afAuth.authState;
  }

  login(){
    this.afAuth.auth.signInWithRedirect(new firebase.auth.GoogleAuthProvider())
  }
  logout(){
    this.afAuth.auth.signOut()
  }
}

login.component.ts

import { AuthService } from './../auth.service'
import { Component, OnInit } from '@angular/core';

@Component({
  selector: 'app-login',
  templateUrl: './login.component.html',
  styleUrls: ['./login.component.css']
})
export class LoginComponent{

  constructor(private auth: AuthService) { }

  ngOnInit() {
  }

  login(){
    this.auth.login();
  }

}

bs-navbar.component.ts

import { Component, OnInit } from '@angular/core';
import { AuthService } from '../auth.service';
@Component({
  selector: 'bs-navbar',
  templateUrl: './bs-navbar.component.html',
  styleUrls: ['./bs-navbar.component.css']
})
export class BsNavbarComponent{

  constructor(public auth: AuthService) {
   }

  logout(){
    this.auth.logout();
  }
}

bs-navbar.component.html

<nav class="navbar navbar-expand-md navbar-light bg-light fixed-top">
    <a class="navbar-brand" routerLink="/">O</a>
    <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarsExampleDefault" aria-controls="navbarsExampleDefault" aria-expanded="false" aria-label="Toggle navigation">
      <span class="navbar-toggler-icon"></span>
    </button>

    <div class="collapse navbar-collapse" id="navbarsExampleDefault">
      <ul class="navbar-nav mr-auto">
        <li class="nav-item">
          <a class="nav-link" routerLink="/shopping-cart">Shopping cart</a>
        </li>
        <ng-template #anonymousUser>
          <li class="nav-item">
            <a class="nav-link" routerLink="/login">Login</a>
          </li>
        </ng-template>
        <li ngbDropdown *ngIf="auth.user$ | async as user; else anonymousUser" class="nav-item dropdown">
          <a ngbDropdownToggle class="nav-link dropdown-toggle" id="dropdown01" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
            {{user.displayName}}
          </a>
          <div ngbDropdownMenu class="dropdown-menu" aria-labelledby="dropdown01">
            <a class="dropdown-item" routerLink="/my/orders">My Orders</a>
            <a class="dropdown-item" routerLink="/admin/orders">Manage Orders</a>
            <a class="dropdown-item" routerLink="/admin/products">Manage Prodcuts</a>
            <a class="dropdown-item" (click)="logout()">Log Out</a>
          </div>
        </li>
      </ul>
    </div>
  </nav>

auth.guard.service.ts

import { Injectable } from '@angular/core';
import { AuthService } from './auth.service';
import { Router } from '@angular/router';
import { CanActivate } from '@angular/router';
import { map } from 'rxjs/operators';

@Injectable({
  providedIn: 'root'
})
export class AuthGuardService implements CanActivate{
   constructor(private auth:AuthService, private router: Router) {
   }
   canActivate(): boolean{
   return this.auth.user$.map(user=>{
      if(user) return true;
      this.router.navigate(['./login']);
      return false;
      });
   }
}

Encountering an error in auth.guard.service.ts on the line

return this.auth.user$.map(user=>
.

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

Unable to enhance Request using Typscript in nodejs

In my middleware, I am attempting to enhance the Request by adding a property called user. However, I encountered this error: Property 'user' does not exist on type 'Request<ParamsDictionary, any, any, ParsedQs>' I am trying to u ...

When using the makeStyles hook in a function component with React, Material-UI, and Typescript, an Invalid Hook Call error may

I'm feeling lost and frustrated with my current coding issue. Despite following the guidelines in the (javascript) documentation, I keep encountering the dreaded Invalid Hook Call error. My setup includes TypeScript 4.1.2, React 17.0.1, and React Typ ...

The issue with downloading all files in Firefox persists when attempting to download multiple files simultaneously due to an anchor click

I am currently facing an issue with downloading multiple files using TypeScript in Angular 6. I am receiving an array of blobs from a web API service. Here is the service method used to get multiple blobs for downloading: private downloadTest(): void { ...

The Google authentication API is throwing a OPERATION_NOT_ALLOWED error with status code 400

Utilizing the following API: , everything seems correctly implemented with the token and parameters matching the documentation. However, it continues to result in a 400 OPERATION_NOT_ALLOWED error. Param:- { "email": "<a href="/cdn-cgi/l/email-p ...

Why is the table not sorting when I apply filters?

I am encountering an issue where the data filters and table sorting are not working together. When I apply filters, the sorting functionality stops working. The filters work fine independently, but once applied, they interfere with the sorting feature. Any ...

Nano frontend program

My current project consists of 5 different single-page applications (SPAs): 2 in Angular, 2 in React, and 1 in Vue.js. These SPAs are served by an integrated server that handles routing for each one. I am looking for a way to share data between these app ...

How to display a nested array in TypeScript following a specific structure

Can anyone assist with printing the variable below in the specified format? Data export const shop_items: Inventory:{ Toys{ Balls: { BallId: 001uy, BallName: Soccerball, SignedBy: David_Beckham, }, ...

Guide on transitioning Angular 2 RC 1 (or an earlier version) Forms to the new Forms in Angular 2 RC 2 / RC 4

I am currently in the process of upgrading my Angular 2 RC 1 app to Angular 2 RC 4, and part of this update involves migrating my existing forms to Angular 2 RC 4 New Forms. Could someone provide guidance on how to successfully update my existing forms to ...

Mixing pipe operators with Angular Observables in an array

In my project, I have an interesting scenario where I am using Observables and piping them to multiple functions as shown below. getOrders(filters: any, page: any = 1, orderBy: string = 'deliver_on', sort: string = 'asc') { const op ...

What is the best way to navigate back to the previous page while retaining parameters?

Is there a way to return to the previous page with specific parameters in mind? Any suggestions on how to achieve this? import {Location} from '@angular/common'; returnToPreviousPage(){ this._location.back(); } What I am looking ...

Troubleshooting Docker Angular+Nginx: Decoding the Mystery Behind Error Codes 403 and

Backend of my .net application is running on mssql and frontend is built with Angular. I have successfully configured Docker files and nginx.conf, but I am facing an issue specifically with Angular 17 within Docker. The main problem is that, when accessing ...

Incorporating a TypeScript interface into your Angular project

I recently started learning angular and I believe it's a good practice to include an interface in my code. The DataFetchService service is currently retrieving data from an internal .json file. Can someone guide me on the best approach to implement an ...

How to Show Concealed Text in Material UI Multiline TextField and Obtain Unveiled Text

I am currently using the Material UI TextField component to create a multiline input for messages. My aim is to display a masked version of the text in the GUI while retaining the unmasked text value for processing purposes. Below is the code snippet for ...

Merging JSON Array of Objects from Separate Http Services in Angular 8

I am currently working on a new Angular 8 project where I need to retrieve JSON data from two different services in my component. Both sets of data are arrays of objects. My goal is to merge the objects from these arrays and then post the combined data bac ...

Dynamic tag names can be utilized with ref in TypeScript

In my current setup, I have a component with a dynamic tag name that can either be div or fieldset, based on the value of the group prop returned from our useForm hook. const FormGroup = React.forwardRef< HTMLFieldSetElement | HTMLDivElement, React. ...

Minimize the amount of information retrieved and shown based on the timestamp

I am currently working on storing and retrieving the date of a user request. For creating the timestamp, I use this code: const date = firebase.firestore.FieldValue.serverTimestamp(); This is how I fetch and display the data: <tr class="tr-content" ...

How can I turn off strict null checks in TypeScript when using ESLint?

ESLint keeps flagging my object as potentially null despite having an if statement to check for it. const user: User | null = getUser() if (user) { // if (user !== null) doesn't work either await user.updateProfile({ di ...

Is there a way for me to implement a "view more posts" button on

I need help figuring out how to hide the "Show More" button when there are no posts. I have created a showLoad function and an isLoad state variable, but I'm unsure of how to implement this. The button display logic is dependent on the isLoad state. ...

What is the functionality of input onChange in React when using state management?

Whenever I try to log the value of the input after each onChange event, there seems to be an odd one event delay. For example, if 'some text' is the default input value and I remove the letter 't' by pressing backspace/delete, it first ...

Using Typescript to pass an optional parameter in a function

In my request function, I have the ability to accept a parameter for filtering, which is optional. An example of passing something to my function would be: myFunc({id: 123}) Within the function itself, I've implemented this constructor: const myFunc ...