Adding Mobile Number based login mechanism for auth user in firebase - firebase

Can we implement Firebase for an android app, where I am registering user using Mobile number (Similar to Whatsapp). Users will be sent a code by server which is entered by user in android app to validate the user mobile number and registering him on the server.
Question : Can I use the above method in conjunction with Firebase Auth?
I was earlier going to use MongoDB for my project, but since Firebase has SYNC capabilities, it will be a better choice for storing data. Another good reason is as below:
If a client loses its network connection, your app will continue
functioning correctly.
Every client connected to a Firebase database maintains its own
internal version of any active data. When data is written, it's
written to this local version first. The Firebase client then
synchronizes that data with the remote database servers and with other
clients on a "best-effort" basis.
Very NEW to Firebase, just came to know about firebase (through Google 2016 IO).
https://firebase.google.com/docs/database/android/save-data

Firebase hosting is not for server side processing.
It stores static assets of your website as a world-class high availability CDN. So websites hosted here loads very fast. Even in high-availability scenarios.
So you have to do processing at other server which then connects with firebase and stores userinfo in realtime database.
Firebase has put limits on userinfo to be placed in directly for users auth dashboard.
For detailed userinfo, firebase realtime db is the way to go(from your processing backend to firebase realtime db).
Further Reading: What kind of web applications are Firebase not ideal for?

Related

Using Firebase Security Rules from a web server

Do any of the Firebase Node/JS SDKs support making calls to Firestore from a node server or cloud functions (e.g. nextjs, remix) on a users behalf, respecting security rules for the authenticated user and supporting sessions for multiple simultaneous users?
Use case:
I have a mobile application with Firebase Security rules set up. I want to serve the same data from a server side web application without reimplementing the Firebase security rules on the web server and keeping them in sync.
e.g. if a user requests a post by id, and Firebase rules prevents them from having access to that specific post, I want Firebase to tell me that and for the web server to forward the 403 status to the user.
More info:
I read this:
If you are developing a Web or Node.js application that accesses Cloud Firestore on behalf of end users, use the firebase Client SDK.
Which suggests this should be possible, however my understanding is that:
firebase-js-sdk can only have one user authenticated at a time so would not be safe if handling async calls from multiple users at once
firebase-admin can be run as a specific user, but this can only be done during initializeAdminApp and again would affect all requests that are currently using the firebase-admin import
Is that correct? Are there any other ways to act on behalf of the authenticated user from a web app?
The only thing I can think of would be the REST API…
https://firebase.google.com/docs/firestore/use-rest-api
Do any of the Firebase Node/JS SDKs support making calls to Firestore from a node server or cloud functions (e.g. nextjs, remix) on a users behalf, respecting security rules for the authenticated user and supporting sessions for multiple simultaneous users?
No, the backend SDKs always bypass security rules. Only the web and mobile SDKs that you use inside the client app make use of authentication tokens available from the user's prior sign-in.
You could consider using the REST API instead since it allows you to pass through a client auth token. It will be up to you to manage the transfer of that token manually.

Will my firebase cloud messaging API still work after my realtime database has been deactivated?

I received an e-mail from firebase-noreply #google.com to the tune of:
[Firebase] Your unused Realtime Database ‘my secret’ will be deactivated in 14 day(s)
We've detected the following issue(s) with your security rules:
any logged-in user can read your entire database
any logged-in user can write to your entire database
I have an app on my Raspberry Pi which is available by web, that will send a firebase message to my mobile phone. It will enable a user (any friend of mine that I chose to tell the url to) to track my position. The webpage on my Rpi contains the API key.
Following this e-mail, should I still expect my app to work?
It's a while since I wrote the app but I do find it occasionally useful. The link that firebase sent me to edit my security settings doesn't work. I think I only had an entry in the firebase realtime database to enable me to get an API key. Please forgive me if I am asking a daft question but it has been years since I worked on this.
firebaser here
The email is specific to the Firebase Realtime Database of your project, and won't affect Firebase Cloud Messaging in any way. If calls to FCM succeed before the database is disabled, they will continue to succeed after the database is disabled.
Of course, if your app needs to interact with the database to do its work, that will stop to function when the database is disabled.

Why does Firebase Realtime db work in incognito, etc but not Firebase Cloud Messaging

I'm just getting started with the Firebase ecosystem and doing some investigating before committing to a GCloud database implementation (Datastore vs. Firestore). My target client is Web/browser and my backend services will be in AppEngine.
Tinkering with the cloud messaging quickstart example, it seems that FCM doesn't work in several scenarios (incognito mode, Safari, if permission blocked). However, the friendly chat demo that uses realtime db updates does appear to work in these scenarios.
High level could anyone explain why?
My goal is to subscribe to events for the client to update state, etc without the use of polling. It seems overkill to put these into firestore just to bypass the notifications permission requirements. Any insight is appreciated. These events could be dispatched from several different backend services and are not exclusively bound to db records.
Update
For what I wanted to do, I was able to simply use Firestore and had no needs that targeted specific devices that merited using FCM. Firestore came out of beta since I posted this question and works well for live subscribing to queries that update local state, which is ultimately what I needed to do.
The FCM client works on the promise that it can identify your browser, even when the page is not open. So it needs to persistently be able to identify the browser. It uses an Instance Token for that, which I assume it persists in the local storage of your browser. And since an incognito window has its own local storage, it becomes a separate instance ID.
The Firebase Realtime Database itself does not persist any information about the instance. Instead you pass in all the necessary information when you initialize the FirebaseApp instance, and then get a DatabaseReference. Since the incognito window runs the same code, it's accessing the same information in the database, and thus seeing the same result.
Note that this would be different if you use Firebase Authentication in combination with the Realtime Database. Auth will persist the user token to local storage, so that won't be shared with the incognito window.

Can static web apps access outside services?

I have been working on a web app and I am now looking into hosting said app. This app is a client-side app for right now meaning that all of the work is being done on the clients device and it has no backend other than the web server giving the site to the user for the first time.
I was looking into Heroku but that seems expensive for my app. Then I looked into Firebase Hosting and it looks good but requires the site to have static content. For now I'm pretty sure my app fits that criteria but in the future I would like to have users sign up for accounts and then store the info they give for the app data in a database. Would do database calls to a firebase database make the app non-static/dynamic anymore?
I know I could use Digital Ocean or another server provider but I want to be able to have scaling done for me so I can just focus on the app and not the containers themselves.
It sounds like you might want to build your app with Firebase Authentication for user logins, store data in Firebase Realtime Database, and host all the content on Firebase Hosting. You could probably write the code entirely in JavaScript to run in the browser, but if you did need to write some code on the backend, you could use Cloud Functions for Firebase.

Integrate Firebase Database with FCM

Is there a way to integrate the Firebase real time database with the newly introduced Firebase Cloud Messaging services ?
I am building an app which uses the the Firebase realtime database for storing data. I want to notify my users using push notifications for every new insert in the database. I came across tutorials which teach you how to use FCM, but most of them require you to set up your own server for storing tokens.
Is there a serverless way of integrating Firebase DB with FCM ?
Sending messages to devices based on inserts into the Firebase Database will require you to run a trusted process, typically on an app server that you control. This trusted process listens to the database changes and then calls Firebase Cloud Messaging to send the messages.
For an example of how to send messaging from a node.js script, see my answer here: How to send Firebase Cloud Messaging from a node server?

Resources