Skip to content

Instantly share code, notes, and snippets.

@aanchirinah
Last active May 19, 2020 06:26
Show Gist options
  • Save aanchirinah/9b6f11c9ca7c88bdbb5629ba41118adf to your computer and use it in GitHub Desktop.
Save aanchirinah/9b6f11c9ca7c88bdbb5629ba41118adf to your computer and use it in GitHub Desktop.
Migration file for Verification Token
module.exports = {
up: function(queryInterface, Sequelize) {
return queryInterface.createTable('VerificationTokens', {
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: Sequelize.INTEGER
},
userId: {
type: Sequelize.INTEGER,
allowNull: false,
onUpdate: "cascade",
onDelete: "cascade",
references: { model: "Users", key: "id" }
},
token: {
type: Sequelize.STRING,
allowNull: false
},
createdAt: {
allowNull: false,
type: Sequelize.DATE
},
updatedAt: {
allowNull: false,
type: Sequelize.DATE
}
}).then(() => {
console.log('created VerificationToken table');
return queryInterface.sequelize.query(`
CREATE EVENT expireToken
ON SCHEDULE AT CURRENT_TIMESTAMP + INTERVAL 1 DAY
DO
DELETE FROM verification_tokens WHERE createdAt < DATE_SUB(NOW(), INTERVAL 1 DAY);
`)
}).then(() => { console.log('expireToken event created') });
},
down: function(queryInterface) {
return queryInterface.dropTable('VerificationTokens')
.then(() => {
console.log(‘VericationTokens table dropped’)
return queryInterface.sequelize.query(`DROP EVENT IF EXISTS expireToken`);
}).then(() => { console.log(‘expireToken event dropped’) })
}
};
@aanchirinah
Copy link
Author

Yes @ShejaEddy and you resend the email verification in the callback that validates the JWT token

@ckOfor
Copy link

ckOfor commented May 19, 2020

Hey @aanchirinah this tutorials looks good, waiting for the updated version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment