Is there a way I can check if an error is of type "AuthError" in TypeScript when using Firebase.
I have an Https Callable function that has a try/catch block that includes the following:
try{
await admin.auth().getUser(data.uid); // will throw error if user does not exist
await admin.auth().deleteUser(data.uid);
} catch (error) {
if(error instanceof AuthError) { // error 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");
}
}
}
But I will get 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 using import { AuthError } from "firebase/auth";
to import AuthError.
Is there a way to check if the error is an instance of AuthError? Are my imports correct? I could find no helpful information in the documentation
Thank you