如何将 Firestore 中的数据转换为身份验证用户

问题描述 投票:0回答:1

我使用 Zapier 从 Google 表单中获取答案并将其移至 Firestore 集合中,但我需要获取此数据(包括姓名、密码和电子邮件)并将其转换为 Firebase 身份验证模块上的用户,是否有自动执行此操作的方法?

我需要仅使用 Google Forms 完成注册,但我只知道如何执行相反的方式(在 firestore 中进行身份验证)。

firebase google-cloud-platform google-cloud-firestore firebase-authentication zapier
1个回答
1
投票

您可以使用云函数,该函数会在 Firestore 集合中创建新文档时触发

假设 Zapier 填充的集合名为

usersCreationRequests
。下面的云函数就可以解决这个问题:

const functions = require('firebase-functions');
const admin = require('firebase-admin');
    
admin.initializeApp();
    
exports.createUser = functions.firestore
    .document('usersCreationRequests/{userDocId}')
    .onCreate((snap, context) => {
  
        return admin
            .auth()
            .createUser({
                email: snap.get('email'),
                password: snap.get('password'),
                displayName: snap.get('name')
            })
            .then((userRecord) => {
                console.log('Successfully created new user:', userRecord.uid);
                return null;
            })
            .catch((error) => {
                console.log('Error creating new user:', error);
                return null;
            });
    });
© www.soinside.com 2019 - 2024. All rights reserved.