In order to speed up my development/testing, I am trying to get started with using the Cloud Functions:shell instead of deploying --only functions everytime I make a tiny change.
I am getting an 'invalid-credentials' error though.
This is a basic working index.js file:
const express = require("express");
const functions = require("firebase-functions");
const admin = require("firebase-admin");
admin.initializeApp();
const app = express();
app.get("/say_hi", (req, res) => console.log("HI!"));
exports.oauth = functions.https.onRequest(app);
Here is how I call the function from the shell in the CLI:
> firebase functions:shell
> oauth.get("say_hi")
Output is "HI!" written to the console, which is good.
The problem is when I try using admin.database() as in the following function:
app.get("/get_ref", (req, res) => admin.database().ref("users"));
This is the output error:
"code": "app/invalid-credential",
"message": "Credential implementation provided to initializeApp() via the 'credential' property failed to fetch a valid Google OAuth2 access token with the following error: 'Error fetching access token: 302 Found'"
I've read the docs for '302 found' code ad 'invalid-credentials', but this doesn't tell me much about solving the issue, so I started wondering if I need a service account to initialize the Admin SDK, but that would not make sense as when I run deploy the functions run seamlessly and I can read/write to/from the Realtime DB.
What is the issue here?