Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase function unexpectedly redirecting to accounts.google.com [closed]

I have a simple Firebase Function shown below. When accessed via javascript (CORS), the function's pre-flight option's request (part of the CORS standard) returns a 302 redirect to a url beginning with

https://accounts.google.com/ServiceLogin?service=ah&passive=true&continue=https://appengine.google.com/_ah/conflogin%3Fcontinue%3D

and ending with my function's URL. Here is the entire function in question:

import * as functions from 'firebase-functions';
import * as express from 'express';
import * as cors from 'cors';

const app = express();

app.use(cors({ origin: true }));

app.post('*', async (req, res) => {
  res.setHeader('X-Test', 'OK');
  res.setHeader('Set-Cookie', ['__session=ninja']);
  res.send('OK');
});

app.get('*', async (req, res) => {
  res.setHeader('X-Test', 'OK');
  res.setHeader('Set-Cookie', ['__session=ninja']);
  res.send('OK');
});

export const testing = functions.https.onRequest(app);

As you can see, the function does not contain any redirect logic. If I manually navigate to the redirect link in my browser (the accounts.google.com one), it shows some sort of Google Compute Engine security page, asking for access to my Google Account. Recently, all of my functions, previously working, have started replying with this 302 redirect when I access them via javascript. This is preventing all of my functions from working as intended.

I can't be sure, but I think it started after I tried publishing a function using the Google Cloud Functions cli (rather than the Firebase Functions cli). It feels like publishing a function using the gcloud cli might have triggered a settings change of some kind? I can't find any information on this issue.

Any help is greatly appreciated!

like image 824
John Avatar asked Mar 05 '19 16:03

John


1 Answers

On my goodness, the issue was I had a typo in the functions name! The name of the function was userAccount-testing and I was calling userAccount.testing. Apparently, when you call a non-existent function you get a 302 redirect in response.

I was copy and pasting the different function names in when trying to diagnose this issue and just so happened to never update the . to a -. face palm

like image 172
John Avatar answered Oct 28 '22 07:10

John