'How to import types from Firebase Admin Node.js SDK?
I'm trying to import the DecodedIDToken type (https://firebase.google.com/docs/reference/admin/node/firebase-admin.auth.decodedidtoken) so that I can assign a type to the value in the .then() callback for when I verify an ID token via admin.auth().verifyIdToken().
I'm unable to import the DecodedIDToken type from firebase-admin and I'm not sure what exactly the issue is. Is it because only admin is exported from the firebase-admin module?
import { Request, Response } from "express";
import admin from 'firebase-admin';
admin.initializeApp();
const isAuthenticated = (req: Request, res: Response) => {
const { authorization } = req.headers;
if (authorization == null || !authorization.startsWith("Bearer")) {
return res.status(401).json({ message: "Unauthorized" });
}
const split = authorization.split("Bearer ");
if (split.length !== 2) {
return res.status(401).json({ message: "Unauthorized" });
}
const token = split[1];
try {
admin.auth().verifyIdToken(token)
.then((decodedIdToken: DecodedIDToken) => {
req.userIdToken = decodedIdToken;
})
.catch();
} catch (error) {
console.log("error: " + error);
}
}
export default isAuthenticated;
Solution 1:[1]
Just try it:
import { DecodedIdToken } from 'firebase-admin/lib/auth/token-verifier';
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Bruno Assis Carvalho |
