Tips for accessing Firebase document fields with Angular Firestore (version 7)

My current task involves retrieving a Firebase document property based on the specified model:

After successfully locating a document with this code snippet:

//Users - collection name, uid - document uid.

I am attempting to access the isAdmin property using the following line of code:

However, I keep receiving an undefined result.

Can anyone suggest how this issue can be resolved? My goal is to retrieve the value of the isAdmin property, but I'm unsure of the correct approach.

Answer №1

Figuring out the answer was a breeze:

canActivate(): Observable<boolean> {
  return this.auth.user$
    .pipe(
      switchMap(fireuser => this.userService.get(fireuser.uid).snapshotChanges()),
        map(document => document.payload.data().isAdmin) 
    )
}

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

Retrieve the code from the Firebase console that was previously deployed

I recently set up Firebase functions using Node.js and deployed the code on Firebase. One of the functions was designed to send an email whenever a new user is created. Unfortunately, I seem to have misplaced the code. Is there any way we can retrieve th ...

The variable 'FC' has been defined, however it is not being utilized. This issue has been flagged by eslint's no-unused

After running eslint, I encountered a warning stating that X is defined but never used for every type imported from react or react-native. For example, this warning appeared for FC and ViewProps (refer to the image below). Below is my .eslintrc.js configu ...

Resolving the problem of Turkish uppercase dotted i when using the capitalization pipe in Angular 2

I have created a custom capitalization pipe that successfully capitalizes almost all characters, including converting the Turkish 'ı' character into 'I'. However, I am facing an issue where the 'i' character is also being con ...

Dealing with TypeScript issues while implementing Multer in an Express application

import multer, { FileFilterCallback } from "multer"; import sharp from "sharp"; import { NextFunction, Request, Response } from "express"; const multerStorage = multer.memoryStorage(); const multerFilter = ( req: Request, ...

Content retrieved from the getStaticProps function is not appearing on the page component

Recently, I have delved into the world of Next.js and decided to explore the capabilities of getStaticPaths and getStaticProps in conjunction with firebase for my details page. import firebase from '../../firebase' export const getStaticPaths = ...

Angular dropdown list is malfunctioning when a value is selected

I'm struggling to use the selected value from a dropdown list in my component class. Despite trying various approaches, such as storing the value using ngModel and triggering an event function, I have not been able to make it work. <select [(ngMod ...

Executing Multiple Requests Concurrently in Angular 5 using forkJoin Technique

Important Note The issue lies in the backend, not Angular. The requests are correct. In my Angular5 app, I am trying to upload multiple files at once using rxjs forkJoin. I store the requests in an array as shown in the code below. However, after adding ...

Encountered a problem while trying to set up the Angular Material Library that has been cloned from

Trying to setup a library that has been forked from https://github.com/angular/material2. git clone <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="63040a1723040a170b16014d000c0e">[email protected]</a>:vugar005/m ...

Angular 13: Masking User Input with Reactive Form Controls

Looking to incorporate a phone number input field with formatting in a reactive form. The desired format is (123) 456-7890. For reference, check out this example link: https://stackblitz.com/edit/angular13-reactive-form-validation-y1qwmf?file=src/app/app. ...

Saving a boolean value and a number to Firestore in an Angular application

In my Angular 5 typescript project, I have a form with various input fields and selections. Here is how I am capturing the form values: let locked: boolean = (<HTMLInputElement>document.getElementById("locked")).value; let maxPlayers: number = (& ...

What is the necessity of Angular reflect polyfill for JIT mode?

I recently came across information on the Angular browser support page discussing the JIT compilation and the ES7/reflect polyfill, stating: It is possible to remove if you always utilize AOT and solely rely on Angular decorators. However, a couple of ...

Searching for TypeScript type definitions for the @Angular libraries within Angular 2

After updating my application to Angular2 v2.0.0-rc.1, I am encountering TypeScript compile errors and warnings when webpack bundles my application. These messages appear for any @angular packages referenced in my TypeScript source files: ERROR in ./src/a ...

Tips for successfully linking angular and NGINX Docker containers to Spring without encountering any CORS errors

Whenever I try to send a request to the server, I keep encountering a CORS error. Interestingly, curl requests from the frontend container to the server work perfectly fine when they are on the same network. Additionally, running the containers locally als ...

Develop an rxjs pipeline that merges values according to their type prior to executing them in an async manner using concatMap

In my code, there's an eventStream that deals with different types of events and sends them to the server via HTTP. import { from, Observable } from 'rxjs'; import { concatMap } from 'rxjs/operators'; type Update = number[]; inte ...

What is the best way to convert a date to ISO 8601 format using JavaScript? Are there any built-in functions or methods in

Currently, I am using this function to set the duration: const setDuration = () => { const currentDate = new Date(); const newDate = new Date(currentDate.getTime()); const year = newDate.getUTCFullYear(); const m ...

A method to access a stored value in localStorage that does not involve utilizing the __zone_symbol__value property

I am encountering a problem with localStorage. After storing user information in localStorage, I am unable to retrieve it without using the __zone_symbol__value property of the parsed value. This is how I store data into locaStorage localStorage.setItem(& ...

The elements on the webpage are spilling over with content

I encountered an issue while creating a dashboard with a sidebar on the left side. When adding content to the page, some of it ended up hidden behind the sidebar. I tried using overflow-x:auto and this was the result: https://i.stack.imgur.com/5qHJY.jpg Be ...

Looking to create an interactive audio experience for users with Angular by playing audio on their click events sourced from Firebase?

I am currently developing a dashboard where I aim to enable users to play specific audio files that they select from a table by clicking on a play button. These audio recordings are stored in Firebase storage. The issue I am facing is that when I manually ...

What is the best way to utilize *ngSwitchWhen in a TypeScript environment?

I am currently working with Ionic2 and Angular2 and encountering an issue while trying to implement a segment using ngSwitchWhen. Unfortunately, the functionality is not working as expected and I am receiving an error message. How can I resolve this issue ...

Upon attempting to open Google Maps for the second time, an error message pops up indicating that the Google Maps JavaScript API has been included multiple times on this page

Currently, I am utilizing the npm package known as google-maps and integrating it with an angular material modal to display a map. However, upon opening the map for the second time, an error message is triggered: You have included the Google Maps JavaScri ...