简体   繁体   中英

How do I convert my data from firestore into authentication users

I use Zapier to get the answers from a Google Forms and move them into a Firestore Collection, but I need to get this data (which includes name, password and email) and turn it into users on the Firebase Authentication Module, is there a way to automatically do that?

I need the sign up to be done exclusively with the Google Forms, but I only know how to do the inverse way (authentication into firestore).

You could use a Cloud Function which is triggered when a new document is created in the Firestore collection .

Let's imagine the collection that is populated by Zapier is named usersCreationRequests . The following Cloud Function will do the trick:

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;
            });
    });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM