Skip to content

Commit

Permalink
Merge pull request #66 from iam-abin/dev
Browse files Browse the repository at this point in the history
fix: resolve chat auth and payment issue
  • Loading branch information
iam-abin authored Mar 4, 2025
2 parents a97a78e + f2e8d03 commit 0e73ab1
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 15 deletions.
24 changes: 21 additions & 3 deletions chat/src/frameworks/webSocket/socket.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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');

Expand Down
2 changes: 0 additions & 2 deletions client/src/components/shimmer/table/TableShimmer.tsx
Original file line number Diff line number Diff line change
@@ -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 (
<tbody>
Expand Down
5 changes: 5 additions & 0 deletions client/src/config/socket.ts
Original file line number Diff line number Diff line change
@@ -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}` }
// });


Expand All @@ -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;
1 change: 0 additions & 1 deletion client/src/pages/admin/UsersListPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions client/src/pages/landing/LandingPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ export = {
skip: number,
limit: number,
): Promise<IJobApplicationDocument[] | []> => {
console.log(searchKey);

const searchedJobs: IJobApplicationDocument[] | [] = await jobApplicationModel
.aggregate([
Expand Down
2 changes: 0 additions & 2 deletions job/src/useCases/job/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ export = (dependencies: IDependency) => {
case SEARCH_RESOURCE_TYPES.APPLIED_JOBS: {
jobs = await jobApplicationRepository.searchAppliedJobs(searchKey.trim(), skip, limit);
count = await jobApplicationRepository.searchAppliedJobsCount(searchKey);
console.log("adf",jobs);

break;
}

Expand Down
5 changes: 3 additions & 2 deletions payment/src/controllers/payment/createPayment.controller.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Request, Response } from 'express';
import { IDependency } from '../../frameworks/types/dependency';
import { IJwtPayload } from '@abijobportal/common';

export = (dependencies: IDependency) => {
const {
Expand All @@ -8,8 +9,8 @@ export = (dependencies: IDependency) => {

return async (req: Request, res: Response) => {
const { membershipPlanId, amount } = req.body;
const { userId: candidateId } = req.currentUser!;

const { userId: candidateId } = req.currentUser as IJwtPayload;
const paymentCreated = await createPaymentUseCase(dependencies).execute(
candidateId,
membershipPlanId,
Expand Down
3 changes: 1 addition & 2 deletions payment/src/frameworks/database/mongo/models/payment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { IPayment } from '../../../types/payment';
export interface IPaymentDocument extends mongoose.Document {
candidateId: mongoose.Schema.Types.ObjectId;
membershipPlanId: mongoose.Schema.Types.ObjectId;
stripeId: mongoose.Schema.Types.ObjectId;
}

const paymentSchema = new mongoose.Schema(
Expand All @@ -18,7 +17,7 @@ const paymentSchema = new mongoose.Schema(
required: true,
},
stripeId: {
type: mongoose.Schema.Types.ObjectId,
type: String,
required: true,
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export = {
stripeId: string;
membershipPlanId: string;
}): Promise<IPaymentDocument> => {

const payment = PaymentModel.buildPayment({
candidateId,
membershipPlanId,
Expand Down

0 comments on commit 0e73ab1

Please sign in to comment.