This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import crypto from 'crypto'; | |
const ALGORITHM = 'aes-256-cbc'; | |
const ENCODING = 'hex'; | |
const IV_LENGTH = 16; | |
const KEY = process.env.ENCRYPTION_KEY!; | |
export const encrypt = (data: string) => { | |
const iv = crypto.randomBytes(IV_LENGTH); | |
const cipher = crypto.createCipheriv(ALGORITHM, new Buffer(KEY), iv); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Example to refresh tokens using https://github.com/auth0/node-jsonwebtoken | |
* It was requested to be introduced at as part of the jsonwebtoken library, | |
* since we feel it does not add too much value but it will add code to mantain | |
* we won't include it. | |
* | |
* I create this gist just to help those who want to auto-refresh JWTs. | |
*/ | |
const jwt = require('jsonwebtoken'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import jwt from 'jsonwebtoken'; | |
interface payload { | |
data: object; | |
} | |
type GenerateToken = (data: object) => string; | |
type VerifyToken = ( | |
token: string | |
) => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const sequelize = new Sequelize(config); | |
const umzug = new Umzug({ | |
storage: "sequelize", | |
storageOptions: { | |
sequelize: sequelize | |
}, | |
migrations: { | |
params: [ |