I am using firebase authentication in my react-native app developing.
When I create user using firebase authentication, firebase sends verification email automatically.
But I want firebase not to send verification email when creating user.
This is the code to create user.
try {
var data = await auth().createUserWithEmailAndPassword(this.state.account_email, this.state.account_password);
this.authData = data;
// verification email
// this.authData.user.sendEmailVerification();
} catch(error) {
console.error("[SignUp] onPressSignup() -> error: ", error);
if (error.code === 'auth/email-already-in-use') {
Toast.show({
type: 'error',
text2: "Your email address is already in use.",
});
} else if (error.code === 'auth/invalid-email') {
Toast.show({
type: 'error',
text2: "Your email address is invalid.",
});
} else {
Toast.show({
type: 'error',
text2: error.message,
});
}
}
I also tried to use firebase admin sdk's createUser function.
// user
var userData = {
email: data.email,
password: data.password,
emailVerified: true,
};
var userRecord = await getAuth().createUser(userData);
functions.logger.info("\tuserRecord: ", userRecord.toJSON());
Is there any way to turn off automatically sending verificaiton email?
I solved this finally.
I used firebase admin sdk to create user
When creating user, use random email(that is not real email but with correct email format, ex. 123234@123.com).
once created user, using getAuth().updateUser to change random email to real email.
try {
// random email
var random = Math.floor(Math.random() * 100000);
var randomEmail = random + "@123.com";
functions.logger.info("\t\trandomEmail: " + randomEmail);
// user
var userData = {
email: randomEmail,
password: data.password,
emailVerified: true,
};
var userRecord = await getAuth().createUser(userData);
functions.logger.info("\tuserRecord: " + userRecord.toJSON());
await getAuth().updateUser(userRecord.uid, {
email: data.email,
emailVerified: true,
});
return {
success: true,
docId: userRecord.uid,
};
} catch(error) {
functions.logger.error("createUser() -> error: ", error);
return {
success: false,
error: error.message,
};
}