这是我的代码:
resolve: async (
_root,
{ data: { password, interests, email, ...userData } },
{ prisma }
) => {
console.log('called reg');
const handleError = (error) => {
console.log('error: ', error);
return { token: null, error, userId: null };
};
return admin
.auth()
.createUser({
email,
password,
displayName: `${userData.firstName} ${userData.lastName}`,
})
.then((userRecord) => {
// See the UserRecord reference doc for the contents of userRecord.
console.log('Successfully created new user:', userRecord);
return admin
.database()
.ref('users/' + userRecord.uid)
.set(
{
...userData,
interests,
},
(error) => {
if (error) return handleError(error);
else {
return admin
.auth()
.createCustomToken(userRecord.uid)
.then((token) => {
console.log('token: ', token)
return {
token,
error: null,
userId: userRecord.uid,
};
}, handleError);
}
}
);
}, handleError)
.then((result) => {
console.log('result: ', result);
return result;
});
},
我在我的 graphql 解析器中使用嵌套,我的问题是,为什么最后一个结果然后返回未定义?我无法弄清楚,因为当我登录createCustomToken的回调时,令牌就在那里,所以我确保最终记录结果,但不幸的是,它是未定义的,基本上,我想使用.then并像这样捕获,而不是asyc /await,帮助?
Helenr
相关分类