Reputation: 39
I'm learning React and trying to understand how to make signup with Firebase. Just can't find what am I doing wrong. Thank you all for any help. I'm using a request link from here: https://firebase.google.com/docs/reference/rest/auth?hl=cs
Here is a code of my request:
export const signInUser = () => {
return async (dispatch) => {
const sendSignInRequest = async () => {
const response = await fetch(
"https://identitytoolkit.googleapis.com/v1/accounts:signUp?key=AIzaSyDkDPtv28NKNnAxKYN_RFTG36lp3-IraAE",
{
method: "POST",
body: JSON.stringify({
email: "[email protected]",
password: "12345TREWQ!asd",
returnSecureToken: true,
}),
headers: {
"Content-Type": "application/json",
},
}
).then((res) => {
console.log(res);
return res;
});
return response;
};
try {
const respnseStatus = await sendSignInRequest();
} catch (error) {
console.log(error);
}
};
};
this is what I'm getting from the server:
Response {
type: 'cors',
url: 'https://identitytoolkit.googleapis.com/v1/accounts…ignUp?key=AIzaSyDkDPtv28NKNnAxKYN_RFTG36lp3-IraAE',
redirected: false,
status: 400,
ok: false,
…}
Thank you.
Upvotes: 1
Views: 9756
Reputation: 1386
there are three types of errors maybe you will face in sign up with email and password in firebase
-and by the way you don't need to use then here while you using async/await so your code will be like that
export const signInUser = (email,password) => {
return async (dispatch) => {
const sendSignInRequest = async () => {
const response = await fetch(
"https://identitytoolkit.googleapis.com/v1/accounts:signUp?key=AIzaSyDkDPtv28NKNnAxKYN_RFTG36lp3-IraAE",
{
method: "POST",
body: JSON.stringify({
email: email
password: password
returnSecureToken: true,
}),
headers: {
"Content-Type": "application/json",
},
}
)
const data = await response.JSON();
if (response.ok) {
dispatch({type:'SIGN-UP'})
} else if (!respnose.ok && data.error.message === "EMAIL_EXISTS"){
console.log('this email is already exist')
} else if(!respnose.ok&data.error.message ==="TOO_MANY_ATTEMPTS_TRY_LATER"){
alert('TOO_MANY_ATTEMPTS_TRY_LATER')
}
};
try {
const respnseStatus = await sendSignInRequest();
} catch (error) {
console.log(error);
}
}
};
Upvotes: 3