I'm starting a web system and it will be multi-tenant, I want to do using the firebase database, but I have not yet come up with a way to associate a user with a tenant (company) so he only has access to that company's tree. I use the following method to create a user and authenticate it:
// Criar novo usuário
createUserButton.addEventListener('click', function () {
firebase
.auth()
.createUserWithEmailAndPassword(emailInput.value, passwordInput.value, passwordId.value)
.then(function () {
alert('Bem vindo ' + emailInput.value);
})
.catch(function (error) {
console.error(error.code);
console.error(error.message);
});
});
// Autenticar com E-mail e Senha
authEmailPassButton.addEventListener('click', function () {
firebase
.auth()
.signInWithEmailAndPassword(emailInput.value, passwordInput.value)
.then(function (result) {
console.log(result);
displayName.innerText = 'Bem vindo, ' + emailInput.value;
alert('Autenticado ' + emailInput.value);
})
.catch(function (error) {
console.error(error.code);
console.error(error.message);
});
});
Now my question is how can I add custom information to a user as the company ID so that he has access only to what he has permission.