如何使用Firebase功能创建新用户?

时间:2019-05-10 07:59:48

标签: firebase google-cloud-firestore

我想为firebase添加一个功能,该功能接受电子邮件进行注册,但是由于某种原因该功能不接受传输的数据,因此我创建了一个匿名用户。

我的客户呼叫功能

createInviteUser(email: string) {
    let inviteFunction = firebase.functions().httpsCallable('createInviteUser');

inviteFunction({email})
    .then((result) => {
    // Read result of the Cloud Function.
   console.log(result);
})
    .catch(err=>{
        console.log(err)
    });

}

服务器端功能

exports.createInviteUser = functions.https.onRequest(async (req, res)=> {
    const email = req.body.email;
        admin.auth().createUser({
            email: email,
            emailVerified: false,
            password: 'secretPassword',
            displayName: 'John Doe',
            photoURL: 'http://www.example.com/12345678/photo.png',
            disabled: false
        })
            .then(function (userRecord) {
                // See the UserRecord reference doc for the contents of userRecord.
                console.log('Successfully created new user:', userRecord.uid);
                return res.status(200).send(userRecord);
            })
            .catch(function (error) {
                console.log('Error creating new user:', error);
            });
});

和服务器端日志

12:39:33.697 PM
createInviteUser
Warning, FIREBASE_CONFIG environment variable is missing. Initializing firebase-admin will fail
12:42:21.765 PM
createInviteUser
Function execution started
12:42:21.765 PM
createInviteUser
Billing account not configured. External network is not accessible and quotas are severely limited. Configure billing account to remove these restrictions
12:42:21.792 PM
createInviteUser
Function execution took 27 ms, finished with status code: 204
12:42:22.035 PM
createInviteUser
Function execution started
12:42:22.035 PM
createInviteUser
 Billing account not configured. External network is not accessible and quotas are severely limited. Configure billing account to remove these restrictions
12:42:22.400 PM
createInviteUser
Function execution took 366 ms, finished with status code: 401

0 个答案:

没有答案