Is it possible to verify if an error is of type "AuthError" in TypeScript when using Firebase?
I have a Https Callable function with a try/catch block that looks like this:
try {
await admin.auth().getUser(data.uid); // will throw error if user doesn't exist
await admin.auth().deleteUser(data.uid);
} catch (error) {
if(error instanceof AuthError) { // issue here
if (error.code === "auth/user-not-found") {
logger.error(`Error: auth/user-not-found, Given user ID does not exist in Firebase Authentication`);
throw new https.HttpsError("not-found", "Given user ID does not exist in Firebase Authentication");
}
}
}
However, I receive an error in my IDE at the if statement:
'AuthError' only refers to a type, but is being used as a value here.ts(2693)
I am importing AuthError using
import { AuthError } from "firebase/auth";
. Are my imports correct? How can I determine if the error is an instance of AuthError? The documentation didn't provide any helpful information.
Thank you