NodeJS TypeScript Errors After Installing npm Firebase Admin SDK

I’m working on a Node.js backend using Firebase Admin SDK and TypeScript. After installing the Firebase Admin package (firebase-admin: ^12.1.1), I started encountering the following TypeScript errors and shows type errors of all api:

TSError: ⨯ Unable to compile TypeScript:
src/middleware/auth.ts:21:26 - error TS2339: Property 'id' does not exist on type 'string | JwtPayload'.
  Property 'id' does not exist on type 'string'.

21             uid: decoded.id,
                            ~~
src/middleware/auth.ts:22:27 - error TS2339: Property 'role' does not exist on type 'string | JwtPayload'.
  Property 'role' does not exist on type 'string'.
...

Problem:
I’m using firebase-admin to verify JWT tokens in my middleware. The decoded token (decodedToken) is expected to have properties like id and role, but TypeScript is giving errors indicating that these properties do not exist on the type string | JwtPayload.

Here’s my middleware code:

ts
Copy code
import { Request, Response, NextFunction } from 'express';
import admin from 'firebase-admin';

export const authenticate = async (req: Request, res: Response, next: NextFunction) => {
    const token = req.headers.authorization?.split(' ')[1];

   if (!token) {
        return res.status(401).send({ error: 'No token provided' });
    }

    try {
        const decoded = await admin.auth().verifyIdToken(token);

        // Error: Property 'id' does not exist on type 'string | JwtPayload'
        req.user = {
            uid: decoded.id,
            role: decoded.role
        };

        next();
    } catch (error) {
        return res.status(403).send({ error: 'Unauthorized' });
    }

 The last overload gave the following error.
    Argument of type 'NextHandleFunction' is not assignable to parameter of type 'PathParams'.

43 app.use(bodyParser.json({ limit: "50mb" }));
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

  node_modules/express-serve-static-core/express-serve-static-core.d.ts:38:9
    38         (path: PathParams, ...handlers: RequestHandlerParams[]): T;
               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    The last overload is declared here.

    at createTSError (/Users/ankushtagore/projects/rentara/simplerStayBackend-v1/node_modules/ts-node/src/index.ts:859:12)
};

My package.json

{
  "name": "rentara-backend",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo "Error: no test specified" && exit 1",
    "start": "node dist/app.js",
    "build": "tsc -p .",
    "dev": "nodemon src/app.ts"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "@types/node": "^18.14.2",
    "nodemon": "^2.0.22",
    "sequelize-cli": "^6.6.2",
    "ts-node": "^10.9.1",
    "tslint": "^6.1.3",
    "typescript": "^4.9.5"
  },
  "dependencies": {
    "@sendgrid/mail": "^7.7.0",
    "@supabase/supabase-js": "^2.39.8",
    "aws-sdk": "^2.1325.0",
    "bcrypt": "^5.0.0",
    "body-parser": "^1.20.1",
    "cors": "^2.8.5",
    "cron": "^2.2.0",
    "dotenv": "^8.6.0",
    "express": "^4.18.2",
    "express-serve-static-core": "^0.1.1",
    "firebase-admin": "^12.4.0",
    "path": "^0.12.7",
    "pg": "^8.5.1",
    "pm2": "^5.3.0",
    "sequelize": "^6.32.0",
  }
}

Checked that firebase-admin is properly installed and configured.
Added skipLibCheck to tsconfig.json to ignore type checking in node_modules, but the error persists.
Tried narrowing the type, but Firebase Admin’s token verification doesn’t return the expected id and role properties.
Used inbuilt express parser.

It works when i remove the firebase-admin package

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật