Reputation: 11059
Simple application where I configure the firebase ...
import * as firebase from "firebase/app";
import 'firebase/auth';
const app = firebase.initializeApp(FIREBASE_CONFIG);
firebase.setLogLevel('debug');
app.auth().useDeviceLanguage();
app.auth().settings.appVerificationDisabledForTesting = __DEVELOPMENT__;
Then I configure the database
import 'firebase/firestore';
const database = app.firestore();
database.settings({
host: 'localhost:8080',
ssl: true,
});
With anonymous user
const handleAuthStateChanged = (user) => {
if (!user) {
firebase.auth().signInAnonymously();
}
}
app.auth().onAuthStateChanged(handleAuthStateChanged)
And I tried to get some data
database.collection('events').doc(eventId).withConverter(eventConverter).get();
But I'm receiving this error
@firebase/firestore: Firestore (7.15.0): FirestoreClient Initializing. user= @firebase/firestore: Firestore (7.15.0): MemoryPersistence Starting transaction: Get next mutation batch @firebase/firestore: Firestore (7.15.0): MemoryPersistence Starting transaction: Allocate target @firebase/firestore: Firestore (7.15.0): MemoryPersistence Starting transaction: Execute query @firebase/firestore: Firestore (7.15.0): IndexFreeQueryEngine Using full collection scan to execute query: Query(target=Target(events/1, orderBy: [name (asc)]); limitType=F) @firebase/firestore: Firestore (7.15.0): PersistentStream close with error: FirebaseError: [code=unknown]: Fetching auth token failed: Cannot redefine property: refreshToken
@firebase/firestore: Firestore (7.15.0): Could not reach Cloud Firestore backend. Connection failed 1 times. Most recent error: FirebaseError: [code=unknown]: Fetching auth token failed: Cannot redefine property: refreshToken
This typically indicates that your device does not have a healthy Internet connection at the moment. The client will operate in offline mode until it is able to successfully connect to the backend.
and
FirebaseError: Failed to get document because the client is offline.
If you go to .. https://nps-event.ridermansb.dev/event/1 you will see that it's working.
But locally is not working
Full source code here
https://github.com/Ridermansb/nps-event
Upvotes: 3
Views: 1417
Reputation: 550
When it works online, but not locally you could set the service account that is used online to work locally to.
To do so:
GOOGLE_APPLICATION_CREDENTIALS
environment variable to the location of that file.See more details on https://cloud.google.com/docs/authentication/getting-started
Upvotes: 0
Reputation: 2519
Firebase allows users to Implement its Authentication SDK to your sign in method. By reviewing your codes, I can see that Firebase Authentication anonymous signin method has been used here. It seems to be missing the error handling method in the method. You can refer to signInAonymously method documentation to add the error handling method to get more details about the error.
Upvotes: 1