【发布时间】:2018-04-19 15:18:39
【问题描述】:
我很接近这个。
我编写了一个云函数,它将从 Azure 令牌发送的信息用于自定义铸造 Firebase 令牌并将此令牌发送回客户端。
令牌已正确创建,但未在我的 HTTP 请求中返回。
很遗憾,我的 Firebase 应用导致超时。
函数执行耗时 60002 毫秒,完成状态为:'timeout'
我真的无法理解为什么会这样,因此这篇文章。我的代码有问题,还是我调用 HTTP 请求错误?
这是我从 Firebase Functions 控制台获取的日志。
这是我的代码
// 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;
});
});
});
当我发出这个 HTTP 请求时,我发送的只是一个JSON,看起来像这样:
parameters = [
"uid" : id,
"email" : mail,
"name" : name
]
【问题讨论】:
标签: javascript firebase google-cloud-functions