N
N
NONAME82018-03-13 17:37:06
iOS
NONAME8, 2018-03-13 17:37:06

How to make a multi-user database in Firebase?

I would like to make it so that when creating a user, a separate data node would be created, where only records of a specific user were stored. So that during authorization I could unload not the entire database, but only the user data node I need.
In general, the usual multiplayer mode.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman Aleksandrovich, 2018-03-13
@NONAME8

When creating a user, various information comes in response, but the most important of them is a unique ID. Nobody bothers you immediately after successful registration to create the keys users/user id/ in the database and put the data you need.

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