有一个firebase服务器端(firebase函数)代码,如果给定的userId不存在,则会创建用户。
它通常可以正常工作,但很少失败。
function createUserIfNotExist(userId, userName) {
admin.auth().getUser(userId).then(function (userRecord) {
return userRecord;
}).catch(function (error) {
return admin.auth().createUser({
uid: userId,
displayName: userName,
})
})
}
当给定userId不存在时,admin.auth()。getUser()抛出
{ code: 'auth/user-not-found', message: 'There is no user record corresponding to the provided identifier.' }
所以admin.auth()。在catch子句中调用createUser()。但它有时会失败并出现以下错误
{ Error: The user with the provided uid already exists.
at FirebaseAuthError.Error (native)
at FirebaseAuthError.FirebaseError [as constructor] (/user_code/node_modules/firebase-admin/lib/utils/error.js:39:28)
at new FirebaseAuthError (/user_code/node_modules/firebase-admin/lib/utils/error.js:104:23)
at Function.FirebaseAuthError.fromServerError (/user_code/node_modules/firebase-admin/lib/utils/error.js:128:16)
at /user_code/node_modules/firebase-admin/lib/auth/auth-api-request.js:399:45
at process._tickDomainCallback (internal/process/next_tick.js:135:7)
errorInfo:
{ code: 'auth/uid-already-exists',
message: 'The user with the provided uid already exists.' } }
我的代码是firebase bug还是有问题?