Skip to content

Commit

Permalink
update the cookie set method
Browse files Browse the repository at this point in the history
  • Loading branch information
dsmabulage committed Sep 3, 2024
1 parent 7509624 commit 02a6b2a
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -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 => {
Expand Down

0 comments on commit 02a6b2a

Please sign in to comment.