Encountering an issue with authenticating the user: "The first parameter 'email' must be a valid string."

Currently, I am working on validating a sign-up form and authenticating user email and password using Firebase.

export class SignupPage {

signupForm :FormGroup;
user_name :AbstractControl;
user_email :AbstractControl;
acc_type: AbstractControl;
user_password:AbstractControl;
pushPage: any;
params: Object;
submitAttempt: boolean = false;
emailRegx: any;
label: any = {}; 

user = {} as User;

constructor(public navCtrl: NavController, public navParams: NavParams 
,public formbuilder:FormBuilder,  public alertCtrl: AlertController, private 
afauth: AngularFireAuth) {

this.signupForm = formbuilder.group({
user_name: ['', Validators.compose([Validators.maxLength(30), 
Validators.pattern('[a-zA-Z ]*'), Validators.required])],
user_email: ['', Validators.required],
user_password: ['', Validators.compose([Validators.maxLength(40), 
Validators.required])],
acc_type: ['', Validators.required]
});

}

ionViewDidLoad() {
console.log('ionViewDidLoad SignupPage');
}

showAlert() {
let alert = this.alertCtrl.create({
title: 'Great!',
subTitle: 'We are about to Verify Your Account, verify with 4546!',
buttons: ['Let\'s verify']
});
alert.present();
}

openLoginPage(){
this.navCtrl.push(LoginPage)
}

createAccount(){
this.submitAttempt = true;

if(!this.signupForm.valid){

}
else {
console.log("success!")
this.showAlert()
this.navCtrl.push(EmailverPage)

}

}

async register(user: User){
try{
const result = await 
this.afauth.auth.createUserWithEmailAndPassword(user.user_email , 
user.user_password)
console.log(result);
}

catch(e) {
console.error(e)
}
}


}

HTML Code

<ion-grid>

<ion-row>
<ion-col text-center     col-4 float-end        >
<p class="pagetitle">Create Account</p>
</ion-col>
</ion-row>

<ion-row>
<ion-col col-12 pager> 

<form  class="signupForm" [formGroup]="signupForm">

<ion-item class="input1">
<ion-label floating>
<ion-icon name="person"></ion-icon>

Full Name</ion-label>
<ion-input type="text" [(ngModel)]="user_name" 
formControlName="user_name" 
[class.invalid]="!signupForm.controls.user_name.valid && 
(signupForm.controls.user_name.dirty || submitAttempt)"></ion-input>
</ion-item>
<ion-item *ngIf="!signupForm.controls.user_name.valid  && 
(signupForm.controls.user_name.dirty || submitAttempt)">
<p>Please enter a valid name.</p>
</ion-item>

<ion-item class="">
<ion-label floating>
<ion-icon name="mail"></ion-icon>

Email</ion-label>
<ion-input  formControlName="user_email"  
[(ngModel)]="user_email" pattern=""  type="Email" 
[class.invalid]="!signupForm.controls.user_email.valid && 
(signupForm.controls.user_email.dirty || submitAttempt)"></ion-input>

</ion-item>
<ion-item *ngIf="!signupForm.controls.user_email.valid  && 
(signupForm.controls.user_email.dirty || submitAttempt)">
<p>Please enter a valid email.</p>
</ion-item>

<ion-item> 
<ion-label floating>
<ion-icon name="checkbox"> </ion-icon>
Account type </ion-label>
<ion-select interface="popover" formControlName="acc_type" 
name="acc_type"  [(ngModel)]="acc_type" 
[class.invalid]="!signupForm.controls.acc_type.valid && 
(signupForm.controls.acc_type.dirty || submitAttempt)">
<ion-option value="1" selected="true"> Client </ion-option>
<ion-option value="2"> Company </ion-option>
</ion-select>
</ion-item>

<ion-item *ngIf="!signupForm.controls.acc_type.valid  && 
(signupForm.controls.acc_type.dirty || submitAttempt)">
<p>Please Select Your Account Type.</p>
</ion-item>


<ion-item>
<ion-label floating>
<ion-icon name="lock"></ion-icon> 
Password
</ion-label>
<ion-input   type="password" [(ngModel)]="user_password" 
name="user_password" formControlName="user_password" 
[class.invalid]="!signupForm.controls.user_password.valid && 
(signupForm.controls.user_password.dirty || submitAttempt)"> 
</ion-input>
</ion-item>
<ion-item *ngIf="!signupForm.controls.user_password.valid  && 
(signupForm.controls.user_password.dirty || submitAttempt)">
<p>Please enter a valid email.</p>
</ion-item>

<ion-item class="input2">

<button class="regButton" type="submit" ion-button full 
round  (click)="register(user)" >Sign Up</button>

</ion-item>
</form>
</ion-col>
</ion-row>
<ion-row>
<ion-col col-12 float-end      >
<p style="text-align:center;color: aliceblue;"> Already have an 
account? <a  (click)="openLoginPage()"> Log in </a></p>

</ion-col>
</ion-row>
</ion-grid>



</ion-content>

While testing the code, I encountered the following console message:

Code: "auth/argument-error", Message: "CreateUserWithEmailAndPassword failed: First argument "email" must be a valid string."

Answer №1

To access the form value, use signupForm.value. Then retrieve the user email using signupForm.value.user_email. Repeat this process for the password value. However, it's important to note that user.user_email is not a string.

Below is the complete code:

async register() {
    try {
        if (this.signupForm.valid) {
            const values = this.signupForm.value;
            const result = await this.afauth.auth.createUserWithEmailAndPassword(values.user_email, values.user_password);
            console.log(result);
        }
    } catch(e) {
        console.error('error: ', e);
    }
}

You can eliminate your User object as it does not include the fields user_email and user_password.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Retrieve the maximum value on the x-axis in Highcharts using React

I need to retrieve the maximum value of the x-axis and place an annotation at the very end: y: chart.xAxis[0].max-1 What is the correct syntax to make it work in a React application? You can view a live demo here. ...

Exploring the functionalities of arrays in Typescript: A beginner's guide

Currently, I am working on a react project and building a store within it. Below is the code snippet I have implemented: import React, { useReducer, useEffect } from 'react'; import { v4 as uuid } from 'uuid'; import { Movie, MoviesAct ...

In Angular, I am working on manipulating classes by utilizing the $event parameter within the (click) event

Snippet of HTML code with button functionality <div fxLayout="column"gt; <h4>Click the button to select a service.</h4> <ng-container *ngFor="let service of services;"> <button class="service-button&q ...

How to retrieve video duration in Angular 2 before uploading the file

Is there a way to retrieve the video duration before uploading it in Angular2? I am looking for a solution without using jQuery. Here is the code snippet I have so far: <input type="file" class="form-control" ng2FileSelect [uploader]="uploader" accept= ...

The functionality of ellipsis, which consists of three dots, allows the text to expand

I am trying to implement a feature where the extra text is represented by three dots (...) as an ellipsis, and upon clicking the dots, the text should expand and contract. However, the current code only contracts the text and does not expand it upon clicki ...

What is the reason behind Typescript executing the abstract class before anything else?

I'm currently facing a challenge solving an abstract class problem with Typescript. Let me explain what I am trying to accomplish. There is a class named Sword that extends Weapon. Each Weapon must have certain properties like the damage, but since e ...

Create an object that may have any number of keys, but must have at least one key defined

Is there a way to accomplish this task? type Plant = "rose" | 'tulip' | 'daisy' type PlantCollection = { [p in Plant]?: number } const validPlantCollection: PlantCollection = { rose: 1, daisy: 2 } const emptyCollectionShouldBeRejec ...

Tips for presenting the cards in a professional layout

After creating a group of cards in angular using a for loop, I encountered an issue: <div class="row"> <div *ngFor="let dev_data of data" class="col-3"> <div class="card shadow"> <div class="card-body ...

Creating an Angular Form Array with Radio Buttons

Having difficulties with implementing reactive forms and an array of radio buttons. Here is a glimpse at my form structure: https://i.sstatic.net/C7t2c.png Each row contains player details and I need to select the status for each player. Component sn ...

What steps should I follow to integrate the NextUI Tab component in my NextJS project?

Hi everyone, I am new to NextJS. I recently set up a basic NextJS starter project with NextUI by using the command npx create-next-app -e https://github.com/nextui-org/next-app-template. Now, I am trying to add a tab group with 3 tabs to the default page. ...

Arranging Angular 5 elements by date

I'm seeking assistance with ordering a table of lessons by date in Angular 5. Unfortunately, the orderBy pipe is not available and existing solutions only work for numbers and strings. Here's the structure of my table: <tbody> <tr *ng ...

Is the treatment of an Observable distinct in Lambda compared to a Promise?

We have integrated the NestJS CQRS package into our application, which enables us to create 'sagas' through the generation of RxJS Observables that trigger various background tasks. An issue surfaced when deploying the application on AWS Lambda ...

Identifying the absence of a character at the end of the last line in Node.js to detect

Currently, I am processing data line by line from a buffer. Within the buffer, the data is structured as follows: name,email,phn test1,<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="47332234337607223f262a372b226924282a">[em ...

Optimal strategies for managing request and response within an Express application

I've developed a REST API using express (and typescript) with the following structure: app.ts routes controllers models Query: Where is the ideal location to handle and construct requests/responses? Is it in routes or controllers? I am ...

When transitioning the Next application to Typescript, errors are displayed with JSX, but it functions correctly in the browser

After migrating my Next App from JS to TSX, I noticed that the JSX in my TSX file is showing errors and underlined, even though the app runs fine in the browser. I'm puzzled as to why this inconsistency exists. Can anyone provide assistance in resolvi ...

Specify the data type of a nested object in a React component with TypeScript

Interface Button{ buttonTitle: { name?: string; } } What is the best way to specify a type for the buttonTitle property? ...

An error has occurred during parsing: An unexpected token was found, a comma was expected instead

I encountered an error while running my program (vue3 + element plus), and I'm unsure about the cause. Can someone please assist me? Below is the error description along with an image: 56:23 error Parsing error: Unexpected token, expected "," (11 ...

Obtain a collection of lists stored in Firebase

As I work on creating an Ionic app with a Firebase database, my data structure in Firebase looks like the image below. I am utilizing angularfire2 to retrieve this data: https://i.stack.imgur.com/5akQf.png While I have successfully obtained the list of pa ...

Is it possible to use Firebase Hosting to direct all routes to a single destination, while also including a designated API route?

My configuration for the rewrites in firebase.json would look like this. "rewrites": [ { "source": "/api", "function": "api" }, { "source": "**", "destination& ...

Efficiently sending emails to multiple recipients using Nodemailer and Firebase concurrently

I've been experimenting with various loop functions in order to send emails from my cloud database. The current code is able to send the email successfully, however I am facing an issue where I cannot customize the content of each email for individual ...