-
Notifications
You must be signed in to change notification settings - Fork 370
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Missing Exports #1666
Comments
I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight. |
Having the same issue, can't use |
Any updates on this issue? On Typescript, unable properly catch FirebaseAuthError type exceptions. |
|
FYI - The Firebase App (not admin) also has a similar issue open: firebase/firebase-js-sdk#4551 |
I'm having the same issue. There's currently no way to import For example |
@lahirumaramba Any updates on whether something could be done for this? |
The only solution I have found so far is to:
Example: import { FirebaseError } from "@firebase/util"; // @firebase is included with firebase-admin
try {
// Some firebase stuff...
} catch (error) {
if (error instanceof Error) {
const firebaseError = error as FirebaseError;
console.log(firebaseError.code); // no warnings
}
} Note that this assumes that the |
My approach was to use a type guard: import type { FirebaseAuthError } from 'firebase-admin/lib/utils/error'
export const isFirebaseAuthError = (error: unknown): error is FirebaseAuthError => {
return (error as FirebaseAuthError).code.startsWith('auth/')
} usage: try {
// firebase...
} catch (error) {
if (isFirebaseAuthError(error)) {
console.log(error.message) // here you will have autocomplete
}
} |
Any update on this? |
Any update? |
Guys this is kinda crazy this isn't addressed... error handling and parsing is a very vital part of development. |
This syntax works fine (example), as opposed to importing from import { initializeApp } from "firebase-admin/app";
import { DecodedIdToken, getAuth } from "firebase-admin/auth";
import { Firestore, getFirestore } from "firebase-admin/firestore"; |
This needs to be exported asap. Error handling with admin SDK is a nightmare. |
This works well for my use case, and it can also be generalized for any kind of https://firebase.google.com/docs/reference/admin/error-handling#structure-of-an-api-error |
Got the same issue here. Cannot import anything from ./utils when using ESM directory. This is very inconvenient, as we now have to do some ugly type checking to be sure that we indeed have a Firebase Error. Providing exports in the future would be highly appreciated. |
🔥RIP firebase 🔥 |
Thanks for your patience folks! I understand your frustration. Until we get better error handling implemented in this SDK, I will merge #2151 for now. That should solve most of the issues you have mentioned above. |
With the new changes in #2151 and #2549, the following works. import { initializeApp } from 'firebase-admin/app';
import { getAuth, FirebaseAuthError } from 'firebase-admin/auth';
async function main() {
const app = initializeApp();
const user = await getAuth().getUserByEmail('[email protected]');
}
main().catch((e) => {
if (e instanceof FirebaseAuthError) {
console.log(e.code);
}
}); We will include the changes in the upcoming release. Thanks! |
The above changes are now released in |
[READ] Step 1: Are you in the right place?
template.
with the firebase tag.
google group.
of the above categories, reach out to the personalized
Firebase support channel.
[REQUIRED] Step 2: Describe your environment
[REQUIRED] Step 3: Describe the problem
There are certain files that aren't listed in the
exports
key in thepackage.json
. Namely everything in theutils
folder, as I realized that theFirebaseAuthError
is only exported by theutils/error.js
file, and is nowhere in the Auth namespace. This makes it very difficult to deal with errors in TypeScript, as the usual checking withinstanceof
can't work without the exported class.Not sure if the fix is to make the
utils
folder "public", or to just reexport the contained classes in the correct namespaces.Also, the
utils
folder only exists under the CommonJS build, and not the ESM directory.The text was updated successfully, but these errors were encountered: