I’m trying to integrate with Firestore for the first time on my Next.js project, and everything is working on a local emulator. But when I try to make any request to my live database, I see two requests to Listen, the second of which fails with a 400 response, and both requests are constantly retried for some time:
// 200
https://firestore.googleapis.com/google.firestore.v1.Firestore/Listen/channel?VER=8&database=projects%2Fsocialgames-c36c8%2Fdatabases%2F(default)&RID=76067&CVER=22&X-HTTP-Session-Id=gsessionid&zx=1icfdzdauapt&t=1
// 400
https://firestore.googleapis.com/google.firestore.v1.Firestore/Listen/channel?gsessionid=ItMqy6u1yzZuNQiUX0fh1R58h08ZEU8anXMjDYWwzmA&VER=8&database=projects%2Fsocialgames-c36c8%2Fdatabases%2F(default)&RID=rpc&SID=vIrIIwY2WdPs8oOAW9kG7w&AID=0&CI=0&TYPE=xmlhttp&zx=20g3zdhqv4h7&t=1
This is my code:
'use client';
import { initializeApp, getApps } from 'firebase/app';
import { getAuth } from 'firebase/auth';
import { initializeFirestore} from 'firebase/firestore';
import firebaseConfig from './firebaseconfig';
export const firebaseApp =
getApps().length === 0 ? initializeApp(firebaseConfig) : getApps()[0];
export const auth = getAuth(firebaseApp);
export const db = initializeFirestore(firebaseApp);
import { User as AuthUser } from 'firebase/auth';
import {
addDoc,
collection,
doc,
getDoc,
} from 'firebase/firestore';
import { db } from '@/lib/firebase/clientApp';
import User, { buildUser } from '@/lib/model/user/user';
export async function getOrCreateUser(authUser: AuthUser): Promise<User> {
// This promise rejects with an error
const user = await getDoc(doc(db, 'users', authUser.uid));
...
}
I’ve triple checked the document path is correct – I also tried querying all docs from the ‘users’ collection, as well as adding a doc, but the results are the same. From another question I tried setting experimentalForceLongPolling: true
but that didn’t change anything either. I’ve also updated my security rules to blanket allow all requests, and no dice. The Cloud Firestore console does show a bit of traffic to my backend, but I’m not sure how else to debug this. What am I doing wrong?