I am using Javascript
and Vue
and integrating firebase
with my app
Scenario(Already built)
sign in
page where users sign in emailVerified
property should be true Problem
firebase.auth().createUserWithEmailAndPassword(email, password)
methodSignup method
signup: async (email, password) => {
const user = await firebase.auth().createUserWithEmailAndPassword(email, password)
await user.user.sendEmailVerification()
return `Check your email for verification mail before logging in`
},
Desired solution
I create a new user from the firebase console
I pass email
as a parameter or uid
and that method should send a verification email to the user so they can verify thier email
Completely scrap the signup
method as i don't need it anymore to send a verification mail
Is there anyway to send a verification email without signing in ?
Made by Firebase Composes and sends an email based on the contents of a document written to a specified Cloud Firestore collection.
To generate an email verification link, provide the existing user's unverified email and an optional ActionCodeSettings object. The operation will resolve with the email action link. The email used must belong to an existing user. // Admin SDK API to generate the email verification link.
So you don't pay for verifying an email address, nor for each API call you make, but only for completed verifications through the code that was sent in the SMS message.
Firebase offers a handy tool for that called email verification link, and it's a link you send to your users' emails, they can click it, and it will verify their emails inside of Firebase Authentication. Then you can decide to only give access to verified users, or run a cleaning tool to remove non-verified users after set period of time.
You can use Firebase Authentication to sign in a user by sending them an email containing a link, which they can click to sign in. In the process, the user's email address is also verified. There are numerous benefits to signing in by email: Low friction sign-up and sign-in.
How to send email verification link with firebase using ReactJS? 1 Step 1: Create a React myapp using the following command.#N#npx create-react-app myapp 2 Step 2: After creating your project folder i.e. myapp, move to it using the following command.#N#cd myapp More ...
Example: Initialize the firebase into your project by creating firebase.js file with the following code. Now write some code into your App.js file. Here, When you click on sign-up button the verification email is send to the provided email address. Here is the verification mail.
You could use a Cloud Function to generate an email verification link, and send it to the user through an email microservice like Sendgrid, Mailjet or Mailgun or via your own custom SMTP server.
You would trigger this Cloud Function when a Firebase user is created using the functions.auth.user().onCreate()
event handler.
Since you will create the user through the Firebase console, the Cloud Function will be triggered without the need for the user to sign-in.
Something along these lines:
exports.sendEmailVerification = functions.auth.user().onCreate((user) => {
const email = user.email;
const url = '...' //Optional, see https://firebase.google.com/docs/auth/custom-email-handler
const actionCodeSettings = {
url: url
};
// Use the Admin SDK to generate the email verification link.
return admin.auth().generateEmailVerificationLink(email, actionCodeSettings)
.then((link) => {
// Construct email verification template, embed the link and send the email
// by using custom SMTP server.
// or a microservice like Sendgrid
return ...
})
.catch((error) => {
// Some error occurred.
});
});
You will find here an official example of a Cloud Function that sends an email.
Is there anyway to send a verification email without signing in ?
Verification emails can only be sent from the client-side SDK, and only after the user has signed in. This is done to prevent the ability to abuse Firebase's servers for sending spam.
If the existing email verification flow of Firebase doesn't fit your needs, you can implement your own custom flow and use the Admin SDKs to set the the verification status once they've met your verification requirements.
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