Skip to main content

Steps

1
Generate an Identity Secret Key from the Sayless dash.You will only be able to view this key once. If you lose it, you will have to generate another one.
2
In your backend, hash the user’s email address using HMAC-SHA256 with the secret you just generated.
const { createHmac } = require("crypto");
const validator = require("validator");

async function hashEmail(email) {
try {
const secret = process.env.SAYLESSCHAT_SECRET;

if (!validator.isEmail(email)) {
  throw new Error("Please provide a valid email");
}

const verificationHash = createHmac("sha256", secret)
  .update(email)
  .digest("hex");

return verificationHash;
} catch (err) {
throw err;
}
}

module.exports = hashEmail;
3
Send this code to your frontend and set on the global Sayless object.A great place to use this will be when your user signs in.
 Sayless("UPDATE", {
      name: user.firstName,
      email: user.email,
      emailHash: hash,
    });
4
Now the user is verified and their messages will have a check icon by their name.