Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error 403 Forbidden. No permission to access the URL

I am trying to migrate to firebase. But before that I gave it a small try by performing the following one. I have successfully added and deployed cloud function but am getting a error

Error: Forbidden

Your client does not have permission to get URL /app/lol from this server.

This is occurring on execution of following code:

const functions = require('firebase-functions');
const express = require('express');
const app = express()
// tried adding this as middleware
// const cors = require('core'({origin: true}))
var admin = require('firebase-admin');

// app.use(cors)
var serviceAccount = require("./ServiceAccount.json");

admin.initializeApp({
  credential: admin.credential.cert(serviceAccount),
  databaseURL: "https://<my-app>.firebaseio.com/"
});


app.get('/lol', (req, res) => {
    res.send(`${Date.now()}`);
})

exports.site = functions.https.onRequest(app);

my firebase.json is as following:

{
  "database": {
    "rules": "database.rules.json"
  },
  "hosting": {
    "public": "public",
    "rewrites" :[{
      "source" : "**",
      "function" : "app"
      }],
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ]
  }
}

when i go to the route, it takes me to the google auth and after signing through correct account. I get the error.

Whats the issue here!

like image 584
Aakash Dave Avatar asked Nov 18 '22 03:11

Aakash Dave


1 Answers

2 alternative ways to solve:

  1. you should change

    exports.site = functions.https.onRequest(app); 
    

    to

    exports.app = functions.https.onRequest(app);
    
  2. you could modify firebase.json from

    "rewrites" :[{
        "source" : "**",
        "function" : "app"
    }],
    

    to

    "rewrites" :[{
        "source" : "**",
        "function" : "site"
     }],
    
like image 143
Luca Rocchietti Avatar answered Dec 25 '22 22:12

Luca Rocchietti