I'm using Firebase to register a new user on the web platform, The registration works well and I can see the new user in Firebase console.
But when I check some errors during the registration like duplicate mail for example, I get an error in the dev tools console:
www.googleapis.com/identitytoolkit/v3/relyingparty/signupNewUser?key=.. iucensg Failed to load resource: the server responded with a status of 400 ()
This is my code, hope you can help:
firebase.auth().createUserWithEmailAndPassword($scope.email, $scope.password).then((user) => {
firebase.auth().currentUser.getToken(/* forceRefresh */ true).then(function (idToken) {
var providerID = user.providerData["0"].providerId;
$http({
method: 'POST',
url: url + '/userReg',
data: {
firstName: $scope.firstName,
lastName: $scope.lastName,
providerID
},
headers: {'x-auth': idToken},
}).then(function successCallback(response) {
if (response.status == 200) {
// $scope.$emit('logoutEvent', true);
$sessionStorage.put('ActiveUser', {accToken: idToken, providerID: 'email'});
$scope.$parent.logoutShow = true;
$scope.$parent.diaryShow = true;
$scope.$parent.userShow = true;
$scope.$parent.signInShow = false;
$scope.$parent.registerShow = false;
$window.location.href = '#/diary';
}
}, function errorCallback(response) {
console.log(response.data);
});
}).catch(function (error) {
console.log(error);
});
}).catch(function (error) {
$scope.alertShow = true;
$scope.errorMessage = error.message;
})
Did you change under authentication tab under advanced settings : One account per email address: Allow creation of multiple accounts with the same email address? Try checking that and see if that's a problem.
If catch error
Solution is change word "public" to "build"
Original
{
"hosting": {
"public": "public",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"rewrites": [
{
"source": "**",
"destination": "/index.html"
}
]
}
}
change to
{
"hosting": {
"public": "build",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"rewrites": [
{
"source": "**",
"destination": "/index.html"
}
]
}
}
Change index.html
from
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta
name="description"
content="Web site created using create-react-app"
/>
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
<!--
manifest.json provides metadata used when your web app is installed on a
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
-->
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<!--
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>React App</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.
You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.
To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
</body>
</html>
to
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta
name="description"
content="Web site created using create-react-app"
/>
<link rel="apple-touch-icon" href="logo192.png" />
<link rel="manifest" href="manifest.json" />
<title>React App</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
</body>
</html>
Result run success without error
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With