mirror of
https://github.com/cheveguerra/whaticket-community.git
synced 2026-04-18 11:49:19 +00:00
feat: start using refresh tokens and better session handler
This commit is contained in:
23
backend/src/helpers/CreateTokens.ts
Normal file
23
backend/src/helpers/CreateTokens.ts
Normal 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
|
||||
});
|
||||
};
|
||||
5
backend/src/helpers/SendRefreshToken.ts
Normal file
5
backend/src/helpers/SendRefreshToken.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
import { Response } from "express";
|
||||
|
||||
export const SendRefreshToken = (res: Response, token: string): void => {
|
||||
res.cookie("jrt", token, { httpOnly: true });
|
||||
};
|
||||
Reference in New Issue
Block a user