node.js на firebase отправляет подтверждение пользователя со стороны сервера - PullRequest
0 голосов
/ 29 мая 2018

Я хотел бы создать нового пользователя на стороне сервера, и у меня есть:

import * as express   from 'express'           ;
import * as admin     from 'firebase-admin'    ;
import * as functions from 'firebase-functions';
import * as path      from "path"              ;
import * as math      from 'mathjs'            ;

const accountKeyPath = path.join(__dirname, '../credentials/serviceAccountKey.json');
const accountKey     = require(accountKeyPath);

const adminSDKPath   = path.join(__dirname, '../credentials/spice-ai-firebase-adminsdk.json');
const adminSDK       = require(adminSDKPath);

const firebaseAdmin = admin.initializeApp({
      credential : admin.credential.cert(adminSDK)
    , databaseURL: accountKey['databaseURL']
});

const dbRef = new Proposal(firebaseAdmin, 'datasets');
const auth  = firebaseAdmin.auth()

const app = express();

app.get('/user', (req, res) => {
    res.send('CRUDing user ...');
    createUser(auth)
}

function createUser(auth){
    const email : string = 'person-' + math.round(math.random(1,100),0) + '@gmail.com'
    const phone : string = '+1' +  math.round(math.random()*10000000000,0);
    const passoword : string = email + '-password'



    auth.createUser({
          email         : email
        , emailVerified : false
        , phoneNumber  : phone
        , password     : passoword
        , displayName  : "some name"
        , photoURL     : "https://firebase.google.com/docs/firestore/solutions/arrays"
        , disabled     : false      
    }) 

    .then(userRecord => {

        const user = auth.currentUser;
        console.log("created new user: ", userRecord.uid, user);

    })
    .catch(err => {
        console.log('error: ', err)

    })
}

Я хотел бы отправить подтверждение по электронной почте после создания учетной записи, однако типичный API auth.currentUser.sendEmailVerificationнедоступно, предположительно потому, что firebase не может отслеживать состояние приложения в экспресс-сеансе?Есть ли способ отправить подтверждение по электронной почте со стороны сервера или определить текущего пользователя, не используя мое собственное решение?

...