From 02a6b2a6fdda6cf24e67259bdd2354bfbf24b96e Mon Sep 17 00:00:00 2001 From: Dillepa Mabulage Date: Tue, 3 Sep 2024 16:21:55 +0530 Subject: [PATCH] update the cookie set method --- src/utils.ts | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/utils.ts b/src/utils.ts index a7f30f6..a1179ec 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,24 +1,33 @@ -import { JWT_SECRET, CLIENT_URL } from './configs/envConfig' -import jwt from 'jsonwebtoken' +import { randomUUID } from 'crypto' +import ejs from 'ejs' import type { Response } from 'express' -import type Mentor from './entities/mentor.entity' -import path from 'path' +import jwt from 'jsonwebtoken' import multer from 'multer' -import ejs from 'ejs' -import { MenteeApplicationStatus, MentorApplicationStatus } from './enums' -import { generateCertificate } from './services/admin/generateCertificate' -import { randomUUID } from 'crypto' +import path from 'path' import { certificatesDir } from './app' +import { CLIENT_URL, JWT_SECRET, REFRESH_JWT_SECRET } from './configs/envConfig' import type Mentee from './entities/mentee.entity' +import type Mentor from './entities/mentor.entity' +import { MenteeApplicationStatus, MentorApplicationStatus } from './enums' +import { generateCertificate } from './services/admin/generateCertificate' export const signAndSetCookie = (res: Response, uuid: string): void => { const token = jwt.sign({ userId: uuid }, JWT_SECRET ?? '') + const refreshToken = jwt.sign({ userId: uuid }, REFRESH_JWT_SECRET ?? '', { + expiresIn: '10d' + }) res.cookie('jwt', token, { httpOnly: true, maxAge: 5 * 24 * 60 * 60 * 1000, secure: false // TODO: Set to true when using HTTPS }) + + res.cookie('refreshToken', refreshToken, { + httpOnly: true, + maxAge: 10 * 24 * 60 * 60 * 1000, + secure: false // TODO: Set to true when using HTTPS + }) } export const getMentorPublicData = (mentor: Mentor): Mentor => {