diff --git a/chat/src/frameworks/webSocket/socket.ts b/chat/src/frameworks/webSocket/socket.ts index 302375e..65d177b 100644 --- a/chat/src/frameworks/webSocket/socket.ts +++ b/chat/src/frameworks/webSocket/socket.ts @@ -1,7 +1,7 @@ import { Server, Socket } from 'socket.io'; import http from 'http'; -import { BadRequestError, NotFoundError } from '@abijobportal/common'; +import { BadRequestError, NotFoundError, verifyJwtToken } from '@abijobportal/common'; import userRepository from '../repositories/mongo/user.repository'; import messageRepository from '../repositories/mongo/message.repository'; import chatRoomRepository from '../repositories/mongo/chatRoom.repository'; @@ -51,16 +51,34 @@ export const setupSocketIO = (httpServer: http.Server): void => { }, }); + io.use((socket, next) => { + const accessToken = socket.handshake.auth?.accessToken; // Get accessToken from handshake auth + + if (!accessToken) { + return next(new Error("Authentication failed: No accessToken provided")); + } + + try { + const decoded = verifyJwtToken(accessToken.substring("Bearer ".length)); + socket.data.user = decoded; // Store user data in socket object + next(); // Proceed with the connection + } catch (err) { + return next(new Error("Authentication failed: Invalid accessToken")); + } + }); + io.on('connection', (socket: Socket) => { onSocketConnection(io, socket); }); }; export const onSocketConnection = (io: Server, socket: Socket): void => { - console.log(`||| A New user connected ,socket id is: ${socket.id} ||| `); - + const { userId } = socket.data.user + console.log(`||| A New user ${socket.data.user.userId} connected ,socket id is: ${socket.id} ||| `); + // addUserToOnline(userId, socket.id); // to get or create the rooms of user socket.on('createChatRoom', async (senderId: string, recepientId: string) => { + try { console.log('In createChatRoom event'); diff --git a/client/src/components/shimmer/table/TableShimmer.tsx b/client/src/components/shimmer/table/TableShimmer.tsx index 7c55d68..cff3594 100644 --- a/client/src/components/shimmer/table/TableShimmer.tsx +++ b/client/src/components/shimmer/table/TableShimmer.tsx @@ -1,6 +1,4 @@ const TableShimmer = ({ columnCount, rowCount }: { columnCount: number; rowCount: number }) => { - console.log(Array.from({ length: rowCount })); - console.log(Array.from({ length: columnCount })); return (
diff --git a/client/src/config/socket.ts b/client/src/config/socket.ts index 1a74281..9476138 100644 --- a/client/src/config/socket.ts +++ b/client/src/config/socket.ts @@ -1,12 +1,16 @@ import { io, Socket } from "socket.io-client"; import { DEVELOPMENT_ORIGIN } from "./baseUrl"; +import { getItemFromLocalStorage } from "../utils/localStorage"; +import { LOCAL_STORAGE } from "../utils/constants"; +const token: string | null = getItemFromLocalStorage(LOCAL_STORAGE.ACCESS_TOKEN); // const socket: Socket = io(PRODUCTION_ORIGIN, { // transports: ["websocket"], // path: "/api/v1/chat/socket.io", // withCredentials: true, // autoConnect: false, +// auth: { token: `Bearer ${token}` } // }); @@ -16,6 +20,7 @@ const socket: Socket = io(DEVELOPMENT_ORIGIN, { path: "/api/v1/chat/socket.io", withCredentials: true, autoConnect: false, + auth: { accessToken: `Bearer ${token}` } }); export default socket; diff --git a/client/src/pages/admin/UsersListPage.tsx b/client/src/pages/admin/UsersListPage.tsx index 44a734a..efb9cde 100644 --- a/client/src/pages/admin/UsersListPage.tsx +++ b/client/src/pages/admin/UsersListPage.tsx @@ -38,7 +38,6 @@ function UsersListPage() { let usersData: IResponse | [] = []; if (isCandidateUrl) { if (!searchKey) { - console.log("no search key"); usersData = await getAllCandidatesApi( currentPage, USERS_PER_PAGE diff --git a/client/src/pages/landing/LandingPage.tsx b/client/src/pages/landing/LandingPage.tsx index 4a3d4e6..9f98f08 100644 --- a/client/src/pages/landing/LandingPage.tsx +++ b/client/src/pages/landing/LandingPage.tsx @@ -110,8 +110,6 @@ function LandingPage() { if (filteredJobs && filteredJobs.data) { dispatch(setCurrentPage(1)); dispatch(setJobs(filteredJobs.data.jobs)); - // console.log(); - dispatch(setTotalNumberOfPages(filteredJobs.data.numberOfPages)); setIsFiltering(true); } else { diff --git a/job/src/frameworks/repositories/mongo/jobApplication.repository.ts b/job/src/frameworks/repositories/mongo/jobApplication.repository.ts index afe0d3a..d37c538 100644 --- a/job/src/frameworks/repositories/mongo/jobApplication.repository.ts +++ b/job/src/frameworks/repositories/mongo/jobApplication.repository.ts @@ -139,7 +139,6 @@ export = { skip: number, limit: number, ): Promise