2
votes

I'm calling Firebase from Google Apps Script.

I am able to connect to Firebase and read/write data using the Firebase Google Apps Script library here https://sites.google.com/site/scriptsexamples/new-connectors-to-google-services/firebase

However this library doesn't seem to have support for the createUser functions. How should I create a new user in Firebase using Apps Script with the function createUserWithEmailAndPassword(email, password)?

Here is what I'm trying to do in Google Apps Script -

function create_user(email, password) {
    var firebaseUrl = "https://myfb.firebaseio.com/";
    var secret = "mysecret";
    var base = FirebaseApp.getDatabaseByUrl(firebaseUrl, secret);

    base.auth().createUserWithEmailAndPassword(email, password)
      .catch(function(error) {
        var errorCode = error.code;
        var errorMessage = error.message;
        Logger.log(errorMessage);
    }); 
}

Any advice appreciated.

Regards Rahul

1

1 Answers

2
votes

You can just use the raw libraries instead of this wrapper script. Use firebase.js client library directly: https://www.gstatic.com/firebasejs/3.6/firebase.js

inject external javascript file in google app script(Google Docs) shows you how to import the external library script.

You can then run your client code:

var config = {
  apiKey: "AIzaS...",
  authDomain: "xxxxxxx.firebaseapp.com",
  databaseURL: "https://xxxxx.firebaseio.com"
}; 
firebase.initializeApp(config);
firebase.auth().createUserWithEmailAndPassword(email, password)...