Firebase kicks out current user

前端 未结 14 1787
一个人的身影
一个人的身影 2020-11-22 01:42

So I have this issue where every time I add a new user account, it kicks out the current user that is already signed in. I read the firebase api and it said that \"I

14条回答
  •  梦如初夏
    2020-11-22 02:02

    You can use firebase function for add users.

    const functions = require('firebase-functions');
    const admin = require('firebase-admin');
    admin.initializeApp();
    
    const cors = require('cors')({
    origin: true,
    });
    exports.AddUser = functions.https.onRequest(( req, res ) => {
    // Grab the text parameter.
    
    cors( req, res, ()  => {
        let email  = req.body.email;
        let passwd = req.body.passwd;
        let role   = req.body.role;
        const token = req.get('Authorization').split('Bearer ')[1];
    
        admin.auth().verifyIdToken(token)
        .then(
                (decoded) => { 
                 // return res.status(200).send(  decoded )
                 return creatUser(decoded);
                })
        .catch((err) => {
                return res.status(401).send(err) 
         });
    
        function creatUser(user){
          admin.auth().createUser({
              email: email,
              emailVerified: false,
              password: passwd,
              disabled: false
            })
            .then((result) => {
              console.log('result',result);
               return res.status(200).send(result);
            }).catch((error) => {
               console.log(error.message);
               return res.status(400).send(error.message);
           })
         }
    
       }); 
     });
    

提交回复
热议问题