Skip to content

Instantly share code, notes, and snippets.

View ChaoLiangSuper's full-sized avatar

Chao Liang ChaoLiangSuper

  • Melbourne
View GitHub Profile
const sequelize = new Sequelize(config);
const umzug = new Umzug({
storage: "sequelize",
storageOptions: {
sequelize: sequelize
},
migrations: {
params: [
@ChaoLiangSuper
ChaoLiangSuper / jwt.ts
Last active May 11, 2019 04:00
JsonWebToken usage 'generate', 'verify' and 'refresh' token
import jwt from 'jsonwebtoken';
interface payload {
data: object;
}
type GenerateToken = (data: object) => string;
type VerifyToken = (
token: string
) => {
@ChaoLiangSuper
ChaoLiangSuper / token-generator.js
Created May 10, 2019 15:09 — forked from ziluvatar/token-generator.js
Example of refreshing tokens with jwt
/**
* 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');
@ChaoLiangSuper
ChaoLiangSuper / encryption.ts
Last active March 24, 2024 14:30 — forked from vlucas/encryption.js
Stronger Encryption and Decryption in typescript
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);