Cloud Functions for Firebase HTTP Timeout

I'm so close to that.

I wrote a cloud-based function that takes information sent from an Azure token to a Firebase custom mint token and sends that token back to the client.

The token is created correctly, but does not return on my HTTP request.

Unfortunately, the Firebase application is causing a timeout.

The execution of the function took 6,0002 ms, completed with the status: 'timeout'

I can not believe why this is so, therefore, this post. Is there something wrong with my code, or am I calling the HTTP request incorrectly?

Here is the log I get from the Firebase console.

Firebase Feature Log

Here is my code

// Create a Firebase token from any UID
exports.createFirebaseToken = functions.https.onRequest((req, res) => {

  // The UID and other things we'll assign to the user.
  const uid = req.body.uid;
  const additionalClaims = {
    name: req.body.name,
    email: req.body.email
  };

  // Create or update the user account.
  const userCreationTask = admin.auth().updateUser(uid, additionalClaims).catch(error => {

    // If user does not exists we create it.
    if (error.code === 'auth/user-not-found') {
      console.log(`Created user with UID:${uid}, Name: ${additionalClaims.name} and e-mail: ${additionalClaims.email}`);
      return admin.auth().createUser({
        uid: uid,
        displayName: displayName,
        email: email,
      });
    }
    throw error;
    console.log('Error!');
  });

  // Wait for all async tasks to complete, then generate and return a custom auth token.
  return Promise.all([userCreationTask]).then(() => {
    console.log('Function create token triggered');
    // Create a Firebase custom auth token.
    return admin.auth().createCustomToken(uid, additionalClaims).then((token) => {
      console.log('Created Custom token for UID "', uid, '" Token:', token);
      return token;
    });
  });
});

When I make this HTTP request, all I send is this JSON, which looks like this:

parameters = [
    "uid" : id,
    "email" : mail,
    "name" : name
]
+4
1

, HTTP-, send(), redirect() end(), .

HTTP- HTTP:

HTTP send(), redirect() end(). . . , Async Promises.

Node.js moment date() HTTP:

const formattedDate = moment().format(format);
console.log('Sending Formatted date:', formattedDate);
res.status(200).send(formattedDate);

, send(), :

// ...
// Create a Firebase custom auth token.
return admin.auth().createCustomToken(uid, additionalClaims).then((token) => {
  console.log('Created Custom token for UID "', uid, '" Token:', token);
  res.status(200).send(token);
  return token;
});
// ...
+2

Source: https://habr.com/ru/post/1688857/


All Articles