# Custom database login - Resend verification if not\_verified

**URL:** <https://community.auth0.com/t/custom-database-login-resend-verification-if-not-verified/51719>\
**Category:** Get Help\
**Tags:** api, auth0, login\
**Created:** [October 17, 2020, 9:48am UTC](https://community.auth0.com/t/custom-database-login-resend-verification-if-not-verified/51719 "2020-10-17T09:48:37Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![blokh](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/blokh/32/24983_2.png) [@blokh](https://community.auth0.com/u/blokh)\
**Post date:** [October 17, 2020, 9:48am UTC](https://community.auth0.com/t/custom-database-login-resend-verification-if-not-verified/51719/1 "2020-10-17T09:48:37Z")

</div>

Greetings,  
I’ve been wondering,  
Is it possible to resend the verification from the custom database’s login script?

I’ll add an example,  
Ofc it fails because I did not add the Authentication to the request ( and Unable to add it. )

```
function login(email, password, callback) {
  const mysql = require('mysql');
  const bcrypt = require('bcrypt');

  const connection = mysql.createConnection({
    host: configuration.DB_HOST,
    user: configuration.DB_USER,
    password: configuration.DB_PASSWORD,
    database: configuration.DATABASE_NAME
  });

  const resendVerificationAndThrowError = (user, callback) => {
  const request = require('request');
  const requestParams = {
    user_id: user.id.toString(),
    client_id: configuration.CLIENT_ID
  };

    request.post("<DOMAIN>/api/v2/jobs/verification-email", requestParams, function(err,httpResponse,body) {
      console.error('error:', err);
      console.log('statusCode:', httpResponse && httpResponse.statusCode); 
      console.log('body:', body);
  });

    return callback(new UnauthorizedError('Please verify your email before loggin in.'));
  };

  connection.connect();

  const query = 'SELECT id, nickname, email, password FROM users WHERE email = ?';

  connection.query(query, [email], function(err, results) {
  if (err) return callback(err);
  if (results.length === 0) return callback(new WrongUsernameOrPasswordError(email));
  const user = results[0];

  bcrypt.compare(password, user.password, function(err, isValid) {
  if (err || !isValid) return callback(err || new WrongUsernameOrPasswordError(email));
  if (!user.email_Verified) return resendVerificationAndThrowError(user, callback);

    callback(null, {
    user_id: user.id.toString(),
    nickname: user.nickname,
    email: user.email
  });
  });
  });
  }

```

Does anyone have a good answer for this?

Thanks in advance,  
Daniel

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [October 19, 2020, 11:19pm UTC](https://community.auth0.com/t/custom-database-login-resend-verification-if-not-verified/51719/3 "2020-10-19T23:19:33Z")

</div>

Hi @blokh,

It may make more sense to do this from a rule, have you considered that?

Here is a thread that goes through how to set it up:

> [@Resend confirmation email rule/button](https://community.auth0.com/t/resend-confirmation-email-rule-button/23734/12):
>
> Hi @dan.woda, Thank you for the quick response slight_smile I tried that already, but none of my users have that, and I do not have permissions to change user metadata either… Could this be because we are using a free account with no subscriptions? We’ve basically only been running tests so far to see if Auth0 fits our needs, and I forgot we did not subscribe for a plan yet - maybe the lack of variable on the user could be because of this?

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [November 3, 2020, 11:19pm UTC](https://community.auth0.com/t/custom-database-login-resend-verification-if-not-verified/51719/4 "2020-11-03T23:19:34Z")

</div>

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.
