next-firebase-auth: Firebase client initialization error when using firebase 9.17.1 (latest)
When filing a bug report, please confirm you’ve done the following:
-
Have you set
onVerifyTokenErrorandonTokenRefreshErrorin your config and checked for any helpful errors? Yes -
Have you set
debug: truein your config and read through server-side and client-side debug logs for any helpful messages? Yes -
Have you tried the example app with your own Firebase credentials? Yes, see below for how I reproduced this using the canary example
-
Have you read through the troubleshooting Q&A? Yes
Describe the bug
When using the client side firebase as shown in the examples in the readme i.e. getFirestore(getApp()) with the latest version of firebase 9.17.1 the error FirebaseError: Firebase: Need to provide options, when not being deployed to hosting via source. (app/no-options). appears.
Seems to be an initialization error because doing my own client side initialization instead, like the example here https://github.com/shadeemerhi/reddit-clone-yt/blob/main/src/firebase/clientApp.ts, works as expected.
Versions
next-firebase-auth version: 1.0.0-canary.19
Firebase JS SDK: 9.17.1
Next.js: 12.2.3 (also experienced same issue in my next@13.1.6 project)
To Reproduce Steps to reproduce the behavior:
- Cloned the repo and added my dev firebase env variables
- Logged in
- Added an example use effect that fetches a document on the
ssr-auth-requiredpage:
import { getApp } from 'firebase/app'
import {getFirestore, doc, getDoc} from 'firebase/firestore';
…
useEffect(() => {
const getUser = async () => {
const ref = doc(getFirestore(getApp()), "events/mtv/users", AuthUser.id);
const docSnap = await getDoc(ref);
if (docSnap.exists()) {
console.log("Document data:", docSnap.data());
} else {
console.log("No such document!");
}
}
getUser();
}, []);
- Works as expected
- Next I updated firebase to latest, and re-ran. I now get the error:
FirebaseError: Firebase: Need to provide options, when not being deployed to hosting via source. (app/no-options). - Next I updated next-firebase-auth to latest canary
yarn add next-firebase-auth@1.0.0-canary.19, but same error persists
Expected behavior Expected the client to be initialized and getFirestore to work, like with previous version of firebase and in the example at https://github.com/gladly-team/next-firebase-auth#using-the-firebase-apps
Debug and error logs
Please provide debug logs or errors from onVerifyTokenError and onTokenRefreshError.
Not relevant
Additional context Add any other context about the problem here. Thank you for any help/explanations!
About this issue
- Original URL
- State: closed
- Created a year ago
- Reactions: 11
- Comments: 35 (13 by maintainers)
Hello, I encountered the same issue when using firebase 9.17 version, works well after downgrading to 9.16. Maybe firebase change the way they init internally @kmjennison
@kmjennison The version of firebase i was using was 9.16.0, which was working with next-firebase-auth 1.0.0-canary.18 as expected and as the examples in the docs show. the example in the repo which uses 9.9.1 works as well.
my confusion on it being a firebase bug or a next-firebase-auth bug is when i initialize firebase myself (doing it the exact same way as here: https://github.com/shadeemerhi/reddit-clone-yt/blob/main/src/firebase/clientApp.ts), prior to next-firebase-auth init, it works with the latest firebase version, 9.17.1
I haven’t had a chance to investigate whether this is a Firebase bug or something in this package. Help welcome!
I reproduced the problem in the example app here, and in that case, it worked when pinning the Firebase client SDK to version 9.16.0.
This solved it for me. I added the initialization right after the
init()command. The issue arose to me when I upgraded to Next 13.The current version doesn’t work with firebase ver > 9.*, you will have to stick with ver 8.9 at the moment. I run into similar issue where the error says firebase.apps is undefined as in ver 9 it uses getApps() but the current lib still uses firebase.apps.