0

I have an application in Angular 16, but when I register a new user in Firebase Authentication, it automatically logs in and replaces the current session with the new registration, when what I really want is for it to register the new email and keep my current session.

register({ email, password, name, phone, address, country, city }: any) {
  return createUserWithEmailAndPassword(this.auth, email, password)
  .then(async(userCredential) => {
  //The user has registered successfully.

  //Now, create a new document in the 'users' collection with the same UID.      
  return this.db.collection('users').doc(userCredential.user.uid).set({ 
    registration_date:  this.currentDate,
    lastUpdate_date:  this.currentDate,
    lastUpdate:  this.currentDate,
    status:  true,
    email: email,
    password: password,
    name: name,
    phone: phone,
    address: address,
    country: country,
    city: city,
    uid: userCredential.user.uid,
    profile_picture: ''
  });
});

}

Please, if someone can tell me what I should do to prevent it from automatically logging in upon registration, but rather keep the current user authenticated, or if I should do it differently, thank you.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
ydct
  • 25
  • 4
  • Creating a user in Firebase through one of its client-side SDKs automatically signs that user in. Wanting to do otherwise typically indicates that you have a use-case that shouldn't be handled client-side, like where an administrator is creating accounts for other users. While Firebase supports such use-cases, they should be handled server-side with one of its Admin SDKs. – Frank van Puffelen Jul 30 '23 at 03:11

0 Answers0