feat: start using refresh tokens and better session handler

This commit is contained in:
canove
2020-09-29 20:30:02 -03:00
parent 3a777dec39
commit c8b4b5bdfe
16 changed files with 209 additions and 46 deletions

View File

@@ -0,0 +1,23 @@
import { sign } from "jsonwebtoken";
import authConfig from "../config/auth";
import User from "../models/User";
export const createAccessToken = (user: User): string => {
const { secret, expiresIn } = authConfig;
return sign(
{ usarname: user.name, profile: user.profile, id: user.id },
secret,
{
expiresIn
}
);
};
export const createRefreshToken = (user: User): string => {
const { refreshSecret, refreshExpiresIn } = authConfig;
return sign({ id: user.id, tokenVersion: user.tokenVersion }, refreshSecret, {
expiresIn: refreshExpiresIn
});
};