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"
}
]
}
}
Cloud Functions for Firebase is a serverless framework that lets you automatically run backend code in response to events triggered by Firebase features and HTTPS requests. Your JavaScript or TypeScript code is stored in Google's cloud and runs in a managed environment.
The solution was to manually add the Cloud Functions Invoker permission to the allUsers user in the Cloud Functions page in the Google Cloud Console. There are several reasons for which you are getting this error message “Your client does not have permission to get URL /… from this server” among them are:
Your client does not have permission to get URL / from this server” “It appears you don’t have permission to access this page.” If you’re on an Nginx server, it will look like this below. Basically, if you see any mention of “forbidden” or “not allowed to access”, you’re probably dealing with a 403 Forbidden error.
However, if you’re hosting elsewhere and your host uses the Apache web server, one common cause of the 403 Forbidden error is a problem in your site’s .htaccess file. The .htaccess file is a basic configuration file used by the Apache web server. You can use it to set up redirects, restrict access to all or some of your site, etc.
It is an HTTP status code. When you encounter this error message, you are basically trying to reach an address or a website that is forbidden to access. Here are examples of some these errors that are commonly thrown: Forbidden: You don't have permission to access [directory] on this server
It must be solved at your GCP Console. Just follow these steps:
And you're good to go!
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With