I am trying to use ReactJS and make a firebase app with a user interface but when I try to do the register and login separately I am getting the error of a duplicate app. I want to know how I can import the firebase credentials like the API key and etc, so I can use firebase essentially in different pages like a registration.js or a login.js
I have tried importing but I am not sure how to do that exactly because I am not familiar with firebase on ReactJS
I am trying to use firebase credentials multiple times in my project and in multiple files and I am trying to pull the API key and config credentials more than once and I am wondering on how to do that or how to set up my firebase/app file
thank you
Related
I have an admin site that has a react frontend, using redux actions, with a node.js app as the server which uses firebase-admin to do the work.
I want to use firestore's onsnapshot listener. but im not sure how this works within the HTTP protocol?
I can't use the firebase-admin from my frontend app, and i cant create realtime DB functionality from the backend within HTTP protocol.
The goal: to set snapshot listeners on my collections from rreact frontend without having to go through multiple authentication processes, considering ive got a separate auth system for admins with my express api.
Is there a solution for this?
EDIT:
my client app is currently initialized with firebase web app config data, but because im authenticating admins with my own express server, the firebase web SDK hasnt authenticated with firebase, so i dont have permission for the data i need. im not sure if i need a service account, or a web app config with extra setup or what
My recommendation is to integrate the Firebase JS SDK into your client app using signInWithCustomToken().
It's not too complicated to do. Though I suppose that depends a lot on how your current auth setup works.
The general idea is this:
Send auth request to your auth service.
Process the request like normal.
Evaluate if the user should have access to Firebase.
If they should, use firebase-admin to create a custom token and send it back to the user.
Use the token on the client to authenticate with Firebase.auth
You should make sure to have Firestore rules to allow admin users to access the data you need.
As an alternative that doesn't use the Firebase client SDK, you could have a long-running node process that opens an onSnapshot. Your react app could receive data from it using either Server-Sent Events or through a WebSocket
In my frontend react project I exported a firebase instance :
firebaseApp.js
import * as firebase from "firebase/app";
import "firebase/auth";
import "firebase/storage";
export default firebase.initializeApp({
... <props>
});
Whenever I need to use firebase in my project, I do this :
import firebaseApp from "../firebase/firebaseApp";
[...]
await firebaseApp.auth().signInWithEmailAndPassword(email, password)
Knowing that Javascript is put client side as this is a frontend project, is there a way for people to open the browser console, access my instance of firebase and call for example :
firebaseApp.auth().createUserWithEmailAndPassword(email, password);
which will result in creating users without backend authorization, and allow bots to create users ?
Iow, can someone access a module instance from the browser and play with it ?
It is indeed possible to take the configuration data from your existing web app, and use that to call the API in another way than your code does. And that does indeed mean that users can create accounts outside of your app.
Firebase makes a clear split between authentication (the users prove who they are) and authorization (the is is granted access to data). Firebase Authentication takes care of the former, while you use security rules (see below) or server-side code to take care of the latter.
For this reason you should never trust that the code that accesses your project is the same code that you wrote. So instead of assuming it's your application, think of what you want a user (no matter what code they use) to be able to do.
For example, if you're using one of the Firebase's databases (the Realtime Database or Cloud Firestore), you'd use their built-in server-side security rules to ensure any user can only access the data they're authorized for. In that case it doesn't matter if the user used your code, or wrote their own code: they'll have to follow those server-side security rules.
This is a common concern, so I recommend also reading some of these questions and answers:
Is it safe to expose Firebase apiKey to the public?
Restrict access to Firebase storage so only my app can access it
Locking down Firebase DB access to specific apps
--First time poster, mods please let me know if the question is inappropriate/incorrect--
Situation:
I'm working on an app with friends. We have a dedicated frontend layer and a dedicated nodejs server running MongoDB. I am trying to integrate firebase into our server layer so we can login users and handle minting/verifying/refreshing tokens using Firebase Auth.
Problem:
I'm completely lost as to how to use Firebase Auth for this purpose. I've looked through the docs extensively, I first went down the "Getting Started with Firebase on an App", until I realized (I think) that guide was specifically for web applications without a dedicated backend.
Then I looked more into Firebase Auth Admin, which looked more like what I was looking for. I tried messing with custom token creation and other authentication related matters but I fail to be able to log in.
I reached out to friends for help, they recommended getting local login/googleauth working End-to-end using firebase before trying to secure our tokens moreso than they already are.
I'm very lost and not sure if I'm misunderstanding something fundamental or just not applying the right things. I apologize if this is unclear, I'm just trying to allow email/password login using firebase auth to securely authenticate with my MongoDB data (if that's even necessary)
Any guidance would be appreciated!
You're absolutely right with your approach and its possible to use Firebase Auth for just login/signup and rest of all on mongoDB.
There are 2 ways u can implement the Firebase Auth-
Using the sdk provided by Firebase
Using the Admin Auth API
Which ever way you selected, Later on save your UID on your custom Backend (Which is backed by MongoDB)
Just create your API's to verify user identity.
If you're using NodeJs you can follow this tutorial.
I'm new to firebase part and I've one requirement to use firebase as a part of serverless architecture, below mentioned is something I need to do, can expertly guide me what to choose from firebase to achieve the same.
I want to create restful API using firebase with NodeJs with an express module of the node, is it something possible or any alternative way to achieve the same using nodejs?
I want to use the firebase authentication mechanism with nodejs code part, ultimately want to create API using the nodeJS with firebase to authenticate the user, so what to use from firebase to achieve the same?
There would be straight forward API that I want to create including the authentication and data store in cloud using firebase, here do I need to use either firestore or real-time database?
I want to deploy the nodeJs project using firebase with firebase cloud, can give me some more details on like how we can do that, reference link sharing would be appreciated.
I had a basic look into few stuff like firebase client SDK, firebase admin SDK, not sure in my case whether I would require to use client SDK or admin SDK to create restFul API.
Note: I want to use no SQL data base, where various collection I can create and can use the same using firebase, I checked that and firestore would perform the same thing, like to store the JSON data, but wanted to know is there any other way to store data or firestore is the best option?
I checked somewhere on reference link about the cloud function, this function can be triggered based on some event, including some https request trigger as well, wanted to confirm using cloud function to create restful API is the good approach or what is the best way to create API using firebase.
I want to create restful API using firebase with NodeJs with express module of node, is it something possible or any alternative way to achieve the same using nodejs?
Yes it is possible
I want to use the firebase authentication mechanism with nodejs code part, ultimately want to create API using the nodeJS with firebase to authenticate the user, so what to use from firebase to achieve the same?
You can use firebase SDK for authentication
There would be straight forward API that I want to create including the authentication and data store in cloud using firebase , here do I need to use either firestore or real time data base?
If you are asking of the database, then you can use any database of your choice, wheater it is MongoDB, firebase-realtime-database etc
I am using angular firebase in my angular firebase backend panel that I am creating for my mobile apps. However I require to send push notification to devices as admin.
I tried adding firebase-admin however its breaking entire backend with weird errors like . List is quite long
ERROR in ./node_modules/#grpc/grpc-js/build/src/channel.js
Module not found: Error: Can't resolve '../../package' in 'xxxx/backend/node_modules/#grpc/grpc-js/build/src'
What exactly is the issue, why is not compatible with angular and how can I use admin sdk to send push notifications
As far as I know, Firebase admin is not meant to be run in the browser. Are you including it into a NodeJS Web Server or into your Angular Application?