O
O
OstapO2019-08-02 13:07:33
firebase
OstapO, 2019-08-02 13:07:33

How to get a list of users and show it on the front?

Hello! There was a need to pull all registered users from firebase:
5d44095f07f38184091993.png
How to get a list of users on the front (Vue.js)? Use Cloud Functions and admin-sdk ? And how then to call this function in a component?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman Alexandrovich, 2019-08-02
@OstapO

here there are examples from firebase and triggers that you can use https://github.com/firebase/functions-samples
you can try to use Auth trigger quickstart: Welcome Email
as soon as it works write to the database and collect data on the front, but this is not the best the idea is
better to use a function that takes the user's data and puts it in the database. And then pick them up if needed.

export function registerUserWithEmailAndPassword(nickname, email, password) {
    return (dispatch) => {
        firebase.auth()
            .createUserWithEmailAndPassword(email, password)
            .then((user) => {
//вот тут вы получаете юзера данные которые нужно сохранить 
                firebase.database()
                    .ref('usersChat/' + user._user.uid)
                    .set({
                        nickname: nickname,
                        uid: user._user.uid,
                        timestamp: Date.now(),
                        email: email
                    })
                return user
            })
        
            .catch((error) => {
                // Handle Errors here.
                var errorCode = error.code;
                var errorMessage = error.message;
                dispatch({
                    type: types.userRegisterErr,
                    payload: errorMessage
                });
            });
    }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question