3

I'm having trouble accessing a JSON api that is inside of my Firebase account. I'll type "firebase deploy" in my terminal and it'll return the following url,

https://myProjectID.firebaseapp.com

If I then enter it into my browser I get my Index.html page so I know it generally works. But being that I'm trying to access the API I search the URL/api/app which works when I run "firebase serve" but doesn't when I run deploy. It returns the following

ERROR: Forbidden Your client does not have permission to get URL /api/app from this server

however my gmail account is permitted on firebase and everything checks out but firebase & cloud functions still won't let me access my API. Please help.

This is my code.

INDEX.JS

const functions = require("firebase-functions");
const server = require(__dirname,"../server.js");
const api = functions
  .runWith({ memory: "2GB", timeoutSeconds: 120 })
  .https.onRequest(server);

module.exports = {
  api
};

SERVER.JS

const express = require("express");
const path = require("path");
const logger = require("./middleware/logger.js");
const cors = require("cors");

const routes = require("./router/routes.js");

let app = express();

// Init Middleware
app.use(logger);

// Set static folder
app.use(express.static(path.join(__dirname, "public")));
app.use(cors({ origin: true }));
app.use("/", routes);

module.exports = app;

FIREBASE.JSON

{
  "database": {
    "rules": "database.rules.json"
  },
  "hosting": {
    "public": "public",
    "ignore": ["firebase.json", "**/.*", "**/node_modules/**"],
    "rewrites": [
      {
        "source": "**",
        "function": "server"
      }
    ]
  }
}
Doug Stevenson
  • 236,239
  • 27
  • 275
  • 302
RaineOxy
  • 31
  • 1
  • 3
  • You are exporting your function as `app` in `index.js` but in your `firebase.json` hosting configuration expect it to be `server`. Pick one and redeploy. – samthecodingman Feb 23 '20 at 02:48

3 Answers3

5

It must be solved at your GCP Console. Just follow these steps:

  1. Go to your GCP Console and login
  2. On the top menu, select the corresponding Firebase project
  3. On the left menu go to Cloud Functions
  4. Click the checkbox of your function (not the name of the function)
  5. Once selected, on the right menu select "Add member"
  6. On "New member" type allUsers
  7. On the Select function bar, select Cloud Functions -> Cloud functions invoker
  8. Click on "Save" and then "Allow public access" on the pop-up warning

And you're good to go!

  • 1
    Thank Omar, you're a hero! I could not find a solution for this anywhere, you saved me day! – rilar Oct 08 '20 at 14:47
1

Searching around about it, it seems that this is an error that might occurs due to many different reasons. Usually, this is due to the way that you are authenticating on Firebase.

Considering that, I would recommend you to take a look at the following Community posts, for more information, on alternatives to fix the error.

I believe one of these should help you fix your issue.

Let me know if the information helped you!

gso_gabriel
  • 3,115
  • 1
  • 5
  • 16
  • Firebase cloud function “Your client does not have permission to get URL /200 from this server” --- worked. THX – Cristi Maris Jun 26 '20 at 17:28
0

In my case, I got the same error after changing my API cloud function location (region).

The problem was that I forgot to connect to the new API path (which contains the new region name) and I accedently tried to connect my old API path, which does not exist any more!

Hope it will help others... It was a bit frustrating.

genericUser
  • 408
  • 4
  • 12