Firebase kicks out current user

前端 未结 14 1797
一个人的身影
一个人的身影 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:22

    Here is a simple solution using web SDKs.

    1. Create a cloud function (https://firebase.google.com/docs/functions)
    import admin from 'firebase-admin';
    import * as functions from 'firebase-functions';
    
    const createUser = functions.https.onCall((data) => {
      return admin.auth().createUser(data)
        .catch((error) => {
          throw new functions.https.HttpsError('internal', error.message)
        });
    });
    
    export default createUser;
    
    1. Call this function from your app
    import firebase from 'firebase/app';
    
    const createUser = firebase.functions().httpsCallable('createUser');
    
    createUser({ email, password })
      .then(console.log)
      .catch(console.error);
    
    1. Optionally, you can set user document information using the returned uid.
    createUser({ email, password })
      .then(({ data: user }) => {
        return database
          .collection('users')
          .doc(user.uid)
          .set({
            firstname,
            lastname,
            created: new Date(),
          });
      })
      .then(console.log)
      .catch(console.error);
    

提交回复
热议问题