How to Send a User Verification Mail in Web and Firebase ?
Last Updated :
02 Aug, 2024
In this article, we will see how to send the user verification email to the user, so that only verified users can be signed In to their account using Email Password Authentication.
The Drawback of email password authentication is that, when a user signs up using an arbitrary email, firebase allows them to sign up and sign in, Unlike email is arbitrary.
So, A verification email sends to the user, so that we can verify that the email really belongs to that user.
A sample video gives you an idea of what we are going to implement in this article:
Syntax: Send User a Verification Email:
function VerificationEmail() {
firebase.auth().currentUser.sendEmailVerification()
.then(() => {
// Email verification sent!
console.log('Email Verification sent! Check your mail box');
// ...
});
}
Example: Below is the implementation to Send a user Verification mail in Web and Firebase
- index.html: The HTML file contains only two buttons that call the respective method, showUserProfile, and VerificationEmail.
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible"
content="IE=edge">
<meta name="viewport"
content="width=device-width, initial-scale=1.0">
<title>samplefirebaseforweb</title>
<script src=
"https://www.gstatic.com/firebasejs/3.7.4/firebase.js">
</script>
</head>
<body>
<script src="/app.js"></script>
<button onclick="showUserProfile1()">
Show user Profile data using provider</button>
<div>
<button onclick="VerificationEmail()">
Sent Verification Email</button>
</div>
</body>
</html>
- script.js: Javascript file contains the firebase configure file and the Function definition for the method showUserProfile and VerificationEmail.
JavaScript
const firebaseConfig = {
//your configuration code here
};
// Initialize Firebase
const app = firebase.initializeApp(firebaseConfig);
function showUserProfile1() {
const user = firebase.auth().currentUser;
if (user !== null) {
user.providerData.forEach((profile) => {
console.log("Sign-in provider: " + profile.providerId);
console.log(" Provider-specific UID: " + profile.uid);
console.log(" Name: " + profile.displayName);
console.log(" Email: " + profile.email);
console.log(" Photo URL: " + profile.photoURL);
});
}
}
// Method to send the user verification mail
function VerificationEmail() {
firebase.auth().currentUser.sendEmailVerification()
.then(() => {
// Email verification sent!
console.log('Email Verification sent! Check your mail box');
// ...
});
}
Output:
Check out your Mailbox to verify the mail, If you did not find the email, check the junk folder, Spam:
Now your firebase application only allows signing in to the user who has the verified email.
Similar Reads
How to send email verification link with firebase using ReactJS? Email verification is a crucial step in user authentication and account security. It ensures that users provide a valid email address and allows you to verify their identity before granting them access to certain features or functionalities. Firebase, a powerful platform for building web and mobile
3 min read
How to Update User Password in Firebase and Web ? In the previous article, we have done How to get a currently singed-in user in firebase, In this Article we will see how to update the user password. Firebase auth provides us a method called updatePassword that takes a string parameter as a new password. We can do it simply by passing the new passw
3 min read
How to get profile of signed in user in web and firebase ? If you are creating a web app and use the firebase services in your web app project, Then you may also need to show the user profile on the profile page. If you successfully Authenticated the user using any method such as Email Password, Google, Â GitHub, Â Microsoft, etc. Then we can show the Authent
3 min read
Phone Number Verification using Firebase in Android Phone number Firebase Authentication is used to sign in a user by sending an SMS message to the user's phone. The user signs in using a one-time code contained in the SMS message. A sample video is given below to get an idea about what we are going to do in this article. Note that we are going to im
4 min read
How to Get Currently Signed In User in Web and Firebase ? Firebase is the most widely used Database and it has awesome features such as Authentication firestore, and Real-time database, given by firebase, We can integrate firebase into Web, Flutter, and Unity. But In this article, we are going to implement firebase on the web and get the current Signed In
3 min read
How to Change Password of User in Android using Firebase? In many apps, we got a feature to login using our email and password. Sometimes it happens that we forget the password and most of the time there reset our password. Here we are going to implement the same feature to Reset our password using Firebase Authentication. You may refer to the following ar
3 min read