diff --git a/backend/user-service/src/controllers/authController.ts b/backend/user-service/src/controllers/authController.ts index 04f69b6a..31b12dd9 100644 --- a/backend/user-service/src/controllers/authController.ts +++ b/backend/user-service/src/controllers/authController.ts @@ -119,6 +119,9 @@ export const logIn: RequestHandler[] = [ const userWithoutPassword = { id: user.id, role: user.role, + email: user.email, + languages: user.languages, + username: user.username, } as UserWithoutPassword; const accessToken = await generateAccessToken(userWithoutPassword); const refreshToken = await generateRefreshToken(userWithoutPassword); @@ -156,7 +159,7 @@ export async function logOut(req: Request, res: Response) { const refreshToken = req.cookies["refreshToken"]; // If JWT token is stored in a cookie if (refreshToken) { const decoded = (await authenticateRefreshToken( - refreshToken, + refreshToken )) as JwtPayload; const userId = decoded.user.id; // user ID is used for identification if (userId) { @@ -170,7 +173,7 @@ export async function logOut(req: Request, res: Response) { // This means access token has expired console.log("Cannot remove login refresh token from server: " + error); console.log( - "You might have removed it somehow. Suggested that you login again to remove old refreshToken from server.", + "You might have removed it somehow. Suggested that you login again to remove old refreshToken from server." ); console.log("Proceeding with rest of log out procedure..."); } @@ -209,7 +212,7 @@ export const oAuthAuthenticate: RequestHandler[] = [ "Access-Control-Allow-Origin": "*", Accept: "application/json", }, - }, + } ); const resp = await response.text(); @@ -304,13 +307,11 @@ export const oAuthNewUser: RequestHandler[] = [ }); if (user !== null) { - res - .status(400) - .json({ - errors: [ - `Github user with ID ${githubUserId} already exists in the system`, - ], - }); + res.status(400).json({ + errors: [ + `Github user with ID ${githubUserId} already exists in the system`, + ], + }); return; } @@ -531,7 +532,7 @@ export async function updateAccessToken(req: Request, res: Response) { } else { try { const decoded = (await authenticateRefreshToken( - refreshToken, + refreshToken )) as JwtPayload; const userWithoutPassword = decoded.user; @@ -602,7 +603,7 @@ export const updateUserProfile: RequestHandler[] = [ const accessToken = req.cookies["accessToken"]; // If JWT token is stored in a cookie const decoded = (await authenticateAccessToken( - accessToken, + accessToken )) as JwtPayload; const userId = decoded.user.id; // user ID is used for identification diff --git a/backend/user-service/src/middleware/authMiddleware.ts b/backend/user-service/src/middleware/authMiddleware.ts index 3eede2da..fbf1757e 100644 --- a/backend/user-service/src/middleware/authMiddleware.ts +++ b/backend/user-service/src/middleware/authMiddleware.ts @@ -14,6 +14,9 @@ export interface User { export interface UserWithoutPassword { id: number; role: string; + username: string; + email: string; + languages: { id: number; language: string }[]; } export interface JwtPayload { @@ -26,7 +29,7 @@ export interface JwtPayload { export async function verifyAccessToken( req: Request, res: Response, - next: NextFunction, + next: NextFunction ) { const accessToken = req.cookies["accessToken"]; // If JWT token is stored in a cookie @@ -49,7 +52,7 @@ export async function verifyAccessToken( export async function protectAdmin( req: Request, res: Response, - next: NextFunction, + next: NextFunction ) { const accessToken = req.cookies["accessToken"]; // If JWT token is stored in a cookie const decoded = (await authenticateAccessToken(accessToken)) as JwtPayload;