Click here to Skip to main content
15,991,071 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
signup.ts :

TypeScript
 async onSubmit(): Promise<void> {
    if (this.signupForm.valid) {
      const name = this.signupForm.get('name')!.value;
      const email = this.signupForm.get('email')!.value;
      const password = this.signupForm.get('password')!.value;
      const confirmpassword = this.signupForm.get('confirmpassword')!.value;
      this.nomail=true;
      this.noname=true;
      this.nopwd=true;
      const userExists = await this.checkIfUserExists(email);
      if (userExists) {
        this.errorMessage = 'User already exists. Please use a different email.';
        this.userexist=true;
      } else {
        this.errorMessage = null;
        
        await this.addNewUser(name, email, password);
        await this.registeruser(name, email, password);
        this.router.navigate(['/dashboard']); 
      }
    } else {
      console.log('Form is invalid');
    }
  }
  

  async checkIfUserExists(email: string): Promise<boolean> {
    const db = getFirestore();
    const bundleRef = collection(db, "users");
    const q1 = query(bundleRef, where("email", "==", email));
    const nompr1 = await getDocs(q1);
    return !nompr1.empty;
  }

async addNewUser(name: string, email: string, password: string): Promise<void> {
    const db = getFirestore();
    await addDoc(collection(db, "users"), { name, email, password });
  }


  async registeruser(name: string, email: string, password: string): Promise<void> {
    try {
      await this.authservice.register(email, name, password).toPromise(); 
    } catch (error) {
      console.error('Error registering user:', error);
    }
  }


signup.html(doesn't matter the form content) :

HTML
<form [formGroup]="signupForm"  (ngsubmit)="onSubmit()" class="form-detail" action="#" method="post">
</form>


authservice.ts :


TypeScript
login(email: string, password: string): Observable<any> {
    console.log('Logging in user:', email);
    const promise = signInWithEmailAndPassword(this.firebaseAuth, email, password)
      .then(response => {
        console.log('Login successful:', response);
        return response;
      })
      .catch(error => {
        console.error('Login error:', error);
        throw error; 
      });
  
    return from(promise);
  }


What I have tried:

after filling the input fields and pressing the sign up button , nothing happens
errors in dev tools :
signup:1 Uncaught (in promise) Error: A listener indicated an asynchronous response by returning true, but the message channel closed before a response was received
Posted

1 solution

Try running your code in a different browser. There have been a number of reports that extensions such as ghostery are responsible for producing this error, and that it's nothing to do with the code that's running.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900