Vitalii
Vitalii

Reputation: 11071

Can firebase database be accessed from outside the app

I need to implement a possibility to try a full version during some period in my Android app. For this I need to save somewhere the end date of trial period.

I think to use firebase for it where I can save some device id and the end date of trial period.

Can you tell me, is firebase database accessible outside the mobile application? For example, can I use postman to send http requests to update trial end date?

My application does not have any user authentication.

Upvotes: 1

Views: 1503

Answers (2)

Umar Hussain
Umar Hussain

Reputation: 3527

yes firebase database can be accessed outside app via other sdk like javascript. But you have to set the rules so that it can be read without authentication. Also if you want to control who can write to the database you need to have some authentication in firebase so that you can apply write rules.

If you don't want to add any kind of authentication then you are exposing you database to write by anyone.

Upvotes: 5

Renaud Tarnec
Renaud Tarnec

Reputation: 83058

Yes, you could call your Firebase back-end via HTTPS by using a Cloud Function, see https://firebase.google.com/docs/functions/http-events

Within this Cloud Function you could update one or more specific nodes of your Real Time database.

You will find in this official video a good example on how you can read from the database through an HTTP Cloud Function: https://www.youtube.com/watch?v=7IkUgCLr5oA

You could adapt it in such a way you call it via a GET and pass a timestamp as query string parameter and use this time stamp in your Function to write to the database. Something like:

exports.updateTrialPeriodDate = functions.https.onRequest((req, res) => {
   const timestamp = req.query.ts;
   consta trialPeriodDate = new Date(timestamp);

   periodDate = {trialPeriodDate: trialPeriodDate};

   admin.database().ref('/....').update(periodDate)  //  <- set the correct path where you want to write
     .then(() => {
         res.status(200).send("success");
     })
     .catch(error => {
        console.log(error);
        res.status(500).send(err);
     });

});

You would then call this function as follows:

https://us-central1-<your-project-id>.cloudfunctions.net/updateTrialPeriodDate?ts=1528718473

Upvotes: 3

Related Questions