My question is how can I create a system that allows each user who registers to have a profile, that is, if I have x user who registers with his email, password (firebase auth) and also writes his name and surname, I can make a profile for each one (something like social networks)
I have made a lot of progress since I asked the question above (I never published it because reading the documentation I was able to advance), but now I am stuck for several days with something that I cannot do,
As the first paragraph explains , I have a record with firebase auth
const auth = getAuth()
createUserWithEmailAndPassword(auth, email, password)
.then ((userCredential) => {
console.log('Registrado') //Mensaje de registro exitoso
const user = userCredential.user //Guarda el usuario
console.log(user.uid)
console.log(user.email)
backend(user);
})
.catch((error) => {
const errorCode = error.code
const errorMessage = error.message
console.log('error: ' + errorMessage + 'Error code ' + errorCode)
let errorHTML = document.getElementById('error');
errorHTML.innerHTML = errorMessage;
})
And then when I call the backend function, it sends firestore the following:
const backend = async (user) => {
const docRef = await addDoc(collection(db, "users"), {
firstName: firstName,
lastName: lastName,
username: username,
userID: user.uid,
});
console.log("Document written with ID: ", docRef.id);
}
And once all that is sent (which works fine), I would like it to be redirected to a screen where , according to the name it put, the same appears on the screen (in another .jsx file)
From what I read, it was very important to save the uid of each record, so I sent it to firestore as well, but I got bogged down, I greatly appreciate your help.
Cheers
Once the user is already created in authentication and in the user collection you must create a state that saves the user at the time of login, and so you can access the authenticated user in the user state and STATUS="LOAGEADO", here it important is to make use of a Security Context that encapsulates the entire APP
IN YOUR APP.JSX you must encapsulate it in a global context, so you can access the user all the time
And in that context you do the authentication and declare the state of the user