/r/Firebase
Community supported discussions on Google's Firebase platform.
/r/Firebase
public void OnTokenReceived(object sender, TokenReceivedEventArgs token) {
Debug.Log("Received Registration Token: " + token.Token);
}
public void OnMessageReceived(object sender, MessageReceivedEventArgs e) {
Debug.Log("Received a new message from: " + e.Message.From);
}
private void Start()
{
FirebaseApp.LogLevel = LogLevel.Debug;
FirebaseApp.CheckAndFixDependenciesAsync().ContinueWithOnMainThread(task => {
var dependencyStatus = task.Result;
if (dependencyStatus == DependencyStatus.Available) {
// Create and hold a reference to your FirebaseApp,
// where app is a Firebase.FirebaseApp property of your application class.
var app = FirebaseApp.DefaultInstance;
FirebaseMessaging.TokenReceived += OnTokenReceived;
FirebaseMessaging.MessageReceived += OnMessageReceived;
FirebaseMessaging.SubscribeAsync("default");
// Set a flag here to indicate whether Firebase is ready to use by your app.
} else {
Debug.LogError($"Could not resolve all Firebase dependencies: {dependencyStatus}");
// Firebase Unity SDK is not safe to use here.
}
});
// rest of start
hey I'm trying to set up firebase messaging into a app however when I send a Firebase Notification messages it doesn't pop up on my phone. I have notifications turned on and turn on the firebase messaging in my code. I also have my google-services.json
and GoogleService-Info.plist
inside the project.
I am working on a web app where users can login and register. I have been having trouble with database integration. I've switched multiple db, but now I am not sure if my Firestore is set up properly. Do I need to make a collection called users and auto ID for the path after?
Once I log in, it says that the error fetching profile 5 NOT_FOUND, but I've checked everything, and I'm not sure where it's coming from. The user data is being stored in the auth for Firebase but not showing on the Firestore.
I am new to all of this and trying to finish my project, but I keep getting setbacks because of the database integration. I also need to incorporate book and location APIS after this step.
Hey all! I'm setting up Firebase Cloud Functions as a backend for my React Native app. I want to securely store my API keys but am unsure of the best approach.
Google’s documentation recommends using Secret Manager, but it’s a paid service, and I’m hoping to avoid extra costs if possible. My keys would never be exposed client-side since my React Native app only accesses them through Firebase Cloud Functions, so I’m considering storing them in an .env file within my functions directory instead.
Is this a safe enough solution, or are there security risks I should be aware of? Any advice on securely handling API keys in Firebase functions (while keeping costs low) would be appreciated! Thanks in advance!
I have public data available to be read by anyone. Normal user should read 100docs every 100secs. A malicious user can spam reads with a for loop, demolishing my savings. Is there a way to prevent this. Allow 5000 reads for each client everyday. And will it cost me?
Hello everyone,
I am trying to add Firebase to my Flutter project but this is what happens when I try to authenticate:
$ firebase --debug login --reauth
Visit this URL on this device to log in:
// Link
Waiting for authentication...
[2024-11-13T07:42:52.564Z] >>> [apiv2][query] POST
https://accounts.google.com/o/oauth2/token
[none]
[2024-11-13T07:42:52.565Z] >>> [apiv2][body] POST
https://accounts.google.com/o/oauth2/token
[omitted]
[2024-11-13T07:43:07.873Z] <<< [apiv2][status] POST
https://accounts.google.com/o/oauth2/token
200
[2024-11-13T07:43:07.874Z] <<< [apiv2][body] POST
https://accounts.google.com/o/oauth2/token
[omitted]
✔ Success! Logged in as // Email
[2024-11-13T07:43:13.350Z] Error: Timed out.
at Timeout._onTimeout (// Path)
at listOnTimeout (node:internal/timers:564:17)
at process.processTimers (node:internal/timers:507:7)
I have looked in blogs but I can't seem to find the reason this is not working.
I have a function running on cloud run gen2.
It's set to 256Mi memory and 80m cpu. But I am using around 40% of the cpu max.
Is it possible to go down to let's say 65m cpu?
I red somewhere in the documentation to stick with 80m but not sure what it means if I go lower.
Attempts to track down any definitive functional limits in Cloud Firestore--outside of document size and field limits-- seems to be nonexistent and I need more clarification as I properly build-out my database into its production-ready format.
First I’ll include my two questions, then the reason for the questions.
1: Is there any functional limit to the number of documents stored in a communal collection that will be subject to high read rates? The Best Practices documentation mentions the “500/50/5” rule that suggests there might be, but it’s hard to infer without any example. Similarly, this Google-produced video on structuring a Firestore database mentions that multiple users writing to documents in the same collection simultaneously can be problematic before going on to mention that multiple users reading from the same collection is “generally okay”. I need more clarification on the “generally” part— is there a defined operational limit to keep in mind listed somewhere?
2: Is there any functional limit to the number of top-level collections in a database? By that, I’m curious if there’s a suggested limit to keep in mind when considering database performance?
For context, I’m an indie developer with one published, offline-only app, but have been working on a project with a Cloud Firestore backend for the better part of 2024. With my project nearing the point of a viable MVP, it’s time for me to take the structure of my database more seriously given that I’m bootstrapped and costs are a concern— specifically when it comes to free users.
The content generated by paid users is all stored hierarchically to support multi tenancy. Given the necessity to drill down into documents, subcollections, more documents, and more subcollections to access the data data that will be used most, this structure will incur potentially avoidable read costs over time. Because the subscriptions of these users will be paying for those, that’s not a worry. However I will have a reasonable free tier which has led me to consider more creative approaches to reducing all of the reads associated with drilling down into the structure of the database to access the content they’ll be accessing most often. This is where my questions stem from.
For this example, let’s say I have types A through F. My original thought was to store each type as documents in their own top-level collections that would be shared by all free users. Essentially it would just be a horizontal database structure for free users that functioned more akin to a relational database. This is where I’m need more clarity on the 500/50/50 rule.
Thinking of ways to address the 500/50/5 rule concerns is where my question about functional limits on the number of top-level collections comes in; if I need to split these collections to reduce the number of users accessing them at once, my thought is that I could create a top-level collection for each type A through F afor each free user individually as opposed to the other approach.
I realize the more horizontal structure isn’t the intended way to use Firestore, but it seems reasonable in theory despite the fact that it will require more work on the coding side of the house..
Please note: I’m completely blind, so I won’t be able to view any screenshots you share. Please explain the information instead.
When the user registers and doesn't verify with email, the user is added to firebase, and he is automatically signed in to his account even though he's not verified, one of the problems for this is I can register in someone's else's email but not verify it, and if he wants to register later with his email it will tell him that it's already taken.
Is it possible to not register it until it's verified? If not what can I do?
I'm using Firebase Emulator + VS Code to develop locally. Whenever I start a new session, I can add breakpoints and debug my function code just fine. But, if I try to attach the debugger after an hour or so of tinkering with my app, the debugger often does not work. Here's what that looks like
Firebase debugger won't attach
(EDIT: Since Reddit is struggling to display my gif, here's a link to it on Imgur)
How would I even go about debugging something like this? Obviously, it's very frustrating to have to restart Firebase every time I need to debug a function, because I lose all the data I was working with.
Here's my tasks.json
{
"version": "2.0.0",
"tasks": [
{
"label": "Firebase emulators: debug",
"type": "shell",
"command": "firebase emulators:start --inspect-functions --debug",
"presentation": {
"panel": "dedicated"
}
},
]
}
and my launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "Firebase: debug funcs",
"type": "node",
"request": "attach",
"port": 9229,
"restart": true,
"skipFiles": ["<node_internals>/**"]
},
]
}
Hi everyone I'm new to firebase, I am trying to design a game similar to wordle where you can make guesses but it also asks different questions each time before each guess until either 5 questions were asked or the user got the right answer. I am struggling to think of the firestore design for this. What I was thinking for now is have a Games collection where each game has an id,5 questions(which contain the answer) and a boolean answeredCorrectly that starts as false, but im struggling to think how would i have each game once a day and know to show the following game in the games collection. Does anyone have experience with designing something like this? Any help is welcome
I have created a site using Quartz SSG. It works locally when i do npx quartz build -d docs --serve
, but when i try with Firebase Hosting preview commands like below, site doesn't respond much. Either its 404 or returns back to home page.
firebase serve --only hosting
Below are the things which can be used to reproduce ( https://quartz.jzhao.xyz/ )
git clone https://github.com/jackyzha0/quartz.git
npm install
npx quartz build -d docs --serve
npx quartz build -d docs
firebase init
firebase serve --only hosting
Firebase.json (default)
{
"hosting": {
"public": "public",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
]
}
}
Firebase init inputs
=== Project Setup
First, let's associate this project directory with a Firebase project.
You can create multiple project aliases by running firebase use --add,
but for now we'll just set up a default project.
? Please select an option: Use an existing project
? Select a default Firebase project for this directory: zzzyz-361015 (zzzyz)
i Using project zzzyz-361015 (zzzyz)
=== Hosting Setup
Your public directory is the folder (relative to your project directory) that
will contain Hosting assets to be uploaded with firebase deploy. If you
have a build process for your assets, use your build's output directory.
? What do you want to use as your public directory? public
? Configure as a single-page app (rewrite all urls to /index.html)? No
? Set up automatic builds and deploys with GitHub? No
? File public/404.html already exists. Overwrite? No
i Skipping write of public/404.html
? File public/index.html already exists. Overwrite? No
i Skipping write of public/index.html
i Writing configuration info to firebase.json...
i Writing project information to .firebaserc...
+ Firebase initialization complete!
System Info:
Windows 11 Pro
Node: v22.11.0
Firebase: 13.24.2
I thought obsidian notes to web hosting is lot easier so wanted to try this.
Would like to know if Quartz ssg is not supported by Firebase.
My earlier experience was Gatsby and Firebase it works perfectly fine.
hello, i am currently new to flutter x firebase and i am creating an app that uses firebase sms otp authentication. my project is currently on the firebase blaze(pay as you go plan).
I have 2 phone number from different carriers A & B. When i try to use A, i manage to get the sms otp and everything works fine. However when i use B, i received internal error 39 when im trying to verify the phone number to send the sms otp. Both numbers has been tested on multiple devices and the result is still the same.
I've attached my functions codes . Appreciate and help available as im lost now. Thanks <3
edit: both numbers are +60
I am doing an iOS project, which has Firebase. However, when I try to do one particular function to send a verification email, it doesn't connect with the server. How do I debug this error?
Hello, I got sending single messages going to no problem. But I having issues with Multicast/Batch messages.
I am doing the following (python 3.11, firebase_admin 6.6.0)
```
import firebase_admin
from firebase_admin import messaging, credentials
from logging import getLogger
log = getLogger(__name__)
# authenticate with firebase
cred = credentials.Certificate('/tmp/key.json')
firebase_admin.initialize_app(cred)
def send_notifications(fcm_tokens, title, body):
message = messaging.MulticastMessage(
notification=messaging.Notification(title=title, body=body),
tokens=fcm_tokens,
)
log.info("attempting to send batch notifications")
try:
# Send the batch notification
response = messaging.send_multicast(message)
print(f'successfully sent {response.success_count} messages out of {len(tokens)}')
# Handle failed messages
if response.failure_count > 0:
failed_tokens = [
"%s" % tokens[idx][:6] for idx, resp in enumerate(response.responses)
if not resp.success
]
print(f'Failed to send messages to these tokens: {failed_tokens}')
if response.failure_count > 0:
for idx, resp in enumerate(response.responses):
if not resp.success:
print(f"error for token {tokens[idx][:6]}: {resp.exception}")
# try to send notifications
tokens = ['xxx'] # my real working fcm token
send_notifications(tokens, "foo", "test")
```
I get the following:
```
# note i am not actually using token xxx, the token it actually puts out is correct
(venv) dev@dev:~$ python3 /tmp/send_batch.py
Successfully sent 0 messages out of 1
Failed to send messages to these tokens: ['xxx']
Error for token xxx: Operation is not implemented, or supported, or enabled.
(venv) dev@dev:~$
```
I saw the deprecation thing on this https://firebase.google.com/docs/cloud-messaging/send-message?hl=en#python_5 and i was spinning my wheels, so went into `firebase_admin` to poke around, and it seems like its using that correct url
```
error: <HttpError 501 when requesting https://fcm.googleapis.com/v1/projects/TRUNCATED/messages:send returned "Operation is not implemented, or supported, or enabled.". Details: "Operation is not implemented, or supported, or enabled.">
```
if anyone could point out what i am doing wrong it would be greatly appreciated.
So i have an SSR Angular application hosted on Apphosting and its costing me a lot per month. I need this part of my app (static landing pages) to be SSR for SEO purposes. This is not worth the cost, does anyone have any ideas on how i can remedy this?
I'm a designer, but I have some experience with HTML, CSS and JS. I decided to finally start a side project that I have been holding in my mind for years - which is a website related to gaming stuff - and I thought of using it to also improve my skillset in web developing. I always have been interested in learning more about all the concepts, because the knowledge I have is very basic and I don't have any background with the process, terminology and all that.
In true 2024 fashion, I recurred to ChatGPT and Claude to understand where to start and explain my idea, to get a hang of what the setup looks like. I immediately started hands-on creating a project, using Firebase for the auth and database and Vercel for the hosting/deployment and APIs (serverless functions). This was all very "I will just think of what I want to do and do it" approach, so I managed to get stuff to work without worrying too much about how I was doing, the structure, deciding on what tools I was using.
Now I'm getting to the point where I'm think of the future, scalability, user privacy, frameworks... and I know that the way I did it was not the one. Here's where I need help deciding and getting some pointers. For my level of knowledge and preferably without having to scrap my work so far (at least as much as possible) what should I know about each type of setup, like Firebase + Google Cloud or Vercel + other stuff?
AI only takes you so far, I'm asking for answers for questions I don't even know, but what I know is that I want to continue developing because I've been enjoying the entire journey.
Hey all!
I'm using the firebase_ui_auth Flutter package, and the SignInScreen that is part of that. I'm planning on offering Google, Apple, and email/password login options. As a test, I logged in with a non-Gmail Google account using the Google authentication option. This seemed to work perfectly. I then logged out, closed the app, and reopened it.
Now, something important to note is that I'm creating a new anonymous account right when a user opens the app for the first time since I want people to be able to try my app without creating an account, and I need a user ID to reference in the backend as the user goes about trying out the app.
So, back to the issue. I reopened the app, at which point a new anonymous user account was created. I then tried logging back into my account using the same Google authentication option as I did before. At no point did I try creating or logging in with just the email; I only ever used the Google authentication option. When I did, I received the following error: This provider is associated with a different user account.
Now, I've tried searching this error to see how to resolve this but unfortunately there doesn't seem to be anything out there about it (that I could find, at least). Does anyone know how I can go about resolving this issue?
Hello guys,
We have created a flutter app with Firebase and we use SMS/Phone authentication.
In the past month we had 3 sms spikes. Thousands of SMS sent in a matter of seconds (without relative increase in user Sign ups)
This cost us more than 800€ in authentication costs.
I have contacted support but after implementing their solution it happened again. I have blocked some usual countries and then it happened again from another country (Fiji).
SMS authentication is crucial to us but right now I have disabled because we will not be able to afford if it happens again.
Do you have any suggestion of what we can do to prevent this type of behaviour?
Thank you in advance.
P.S: Firebase will not refund us for the charges :)))
I originally used firebase often 2 years ago, but now I'm trying to develop a website using it again...with one issue that I spent all day without success attempting to understand.
"Cannot use import statement outside of a module"
I'm using client-side js, and I've tried everything so far. Require statements, import statements, <script type ="module"> etc. With no luck whatsoever. Here are the lines in question as they currently stand, 400 iterations in:
<script src="https://www.gstatic.com/firebasejs/11.0.1/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/11.0.1/firebase-firestore.js"></script>
<script src="index.js"></script>
import { initializeApp } from "firebase/app";
import { getFirestore, collection, addDoc, serverTimestamp } from "firebase/firestore";
const app = initializeApp(firebaseConfig);
const db = getFirestore(app);
I distinctly remember this once working two years ago. What is off?
This morning, for some reason all new changes to my code stopped being deployed to production when using "firebase deploy". I tried renaming one of the functions in my index.ts assuming that might force some sort of cache to clear or something, but when running firebase deploy the name of my old function came up, and this project is now dead in the water because I can't seem to deploy any new code. Does anyone know what could be happening and how I can make this work again? I'm using VS Code and it's a typescript project.
all these dependencies, different versions of sdk classes between client and admin, react native dependencies.
why would i not just use the rest endpoints to register a user and send the verification email? no dependencies needed. Did I just waste a week?
why are you using the sdk instead of doing this?
https://identitytoolkit.googleapis.com/v1/accounts:signUp?key={{firebasekey}}
https://identitytoolkit.googleapis.com/v1/accounts:sendOobCode?key={{firebasekey}}
Has anyone developed any apps using Vertex AI? Share your experiences!
I have a iOS app that handles bulk sending of images to a group of friends.
As you can imagine the reads from the db were massive, especially if a user opened the images and then re opened them at a later date. To overcome this I created a cache and this has helped drastically.
Most of you might already have done this but if you haven’t it’s worth thinking about
i have a problem adding a custom domain to my firebase account !
can u guys help me make sure im doing it the right way ? (check the screenshots attached)
I have following schema of a item (map) in an array of a field "persons" in a document.
{
id: "abc",
name: "John Doe",
email: "john@example.com",
profession: "serial killer coder",
}
Now, I want to add an affordance for the user to delete/remove only John from the `persons` field using only the id. How do I do that?
Here is what I have tried,
// John's id, which I have access to on the client-side
const personToRemove = { id: "abc" };
await updateDoc(documentRef, {
persons: arrayRemove(personToRemove),
updatedAt: new Date(),
});
But, this isn't doing anything. I have tried AI models (Gemini, Claude) but not helpful.
Please feel free to query anything related to this if this isn't clear. Thanks.
------------------------------------------------------------------------------------------------------------------------------
Edit: SOLVED. Thank you everyone. Here is what I ended up doing.
Prior to deleting, I already had the list of person. I filtered the list client-side and set the document again.
await setDoc(documentRef, {persons: everyoneExpectJohn, updatedAt: new Date()});
Don't know the implication. but it works!
BTW, this was Claude's response 😂, hope you guys find it funny.
I'm wondering, is there an automagic way to trigger an email verification message when users are created using the admin sdk?
I see the admin sdk has methods for creating the links but doesn't look like it sends the emails. Do i have to send my own email if i use the admin sdk or did i miss something?