Skip to content

Commit

Permalink
prettier fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
juslam19 committed Nov 14, 2023
1 parent 877026f commit 11ff72c
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 31 deletions.
9 changes: 4 additions & 5 deletions backend/chat-service/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ io.on("connection", async (socket: Socket) => {
}

const accessToken = getCookie("accessToken"); // if your token is called jwt.
console.log("Access Token: " + getCookie("accessToken"))
console.log("Access Token: " + getCookie("accessToken"));

if (accessToken) {
try {
await authenticateAccessToken(accessToken);

// Middleware ends here
// Listen for room joining.
socket.on("join-room", async (roomId: string, username?: string) => {
Expand All @@ -71,19 +71,18 @@ io.on("connection", async (socket: Socket) => {
// Broadcast to all connected users that this user has joined the room
io.to(roomId).emit("joined-room", username);
});

} catch (error) {
console.log(error);
console.log("Not authorized, access token failed");
// next(new Error("Not authorized, access token failed"));
socket.emit("error", { errorMsg: "Not authorized, access token failed" });
socket.disconnect()
socket.disconnect();
}
} else {
console.log("Not authorized, no access token");
// next(new Error("Not authorized, no access token"));
socket.emit("error", { errorMsg: "Not authorized, no access token" });
socket.disconnect()
socket.disconnect();
}

// Listen for chat messages.
Expand Down
10 changes: 4 additions & 6 deletions backend/collaboration-service/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,6 @@ interface UsersAgreedEnd {

const usersAgreedEnd: UsersAgreedEnd = {};



// Handle other collaboration features.
io.on("connection", async (socket) => {
console.log("New connection:", socket.id);
Expand Down Expand Up @@ -135,26 +133,26 @@ io.on("connection", async (socket) => {
// Send the initial language to this user.
socket.emit("initial-language", initialLanguage);
const initialQuestionId = roomCurrentQuestion[roomId];
if (initialQuestionId) socket.emit("set-first-question", initialQuestionId);
if (initialQuestionId)
socket.emit("set-first-question", initialQuestionId);
// Attach user's username and roomId to this connection
socket.data.username = username;
socket.data.roomId = roomId;
// Broadcast to all connected users that this user has joined the room
io.to(roomId).emit("user-join", username);
});

} catch (error) {
console.log(error);
console.log("Not authorized, access token failed");
// next(new Error("Not authorized, access token failed"));
socket.emit("error", { errorMsg: "Not authorized, access token failed" });
socket.disconnect()
socket.disconnect();
}
} else {
console.log("Not authorized, no access token");
// next(new Error("Not authorized, no access token"));
socket.emit("error", { errorMsg: "Not authorized, no access token" });
socket.disconnect()
socket.disconnect();
}

socket.on("user-agreed-next", async (roomId, userId) => {
Expand Down
6 changes: 3 additions & 3 deletions backend/matching-service/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ io.on("connection", async (socket: Socket) => {
}

const accessToken = getCookie("accessToken"); // if your token is called jwt.
console.log(getCookie("accessToken"))
console.log(getCookie("accessToken"));

if (accessToken) {
try {
Expand All @@ -58,13 +58,13 @@ io.on("connection", async (socket: Socket) => {
console.log("Not authorized, access token failed");
// next(new Error("Not authorized, access token failed"));
socket.emit("error", { errorMsg: "Not authorized, access token failed" });
socket.disconnect()
socket.disconnect();
}
} else {
console.log("Not authorized, no access token");
// next(new Error("Not authorized, no access token"));
socket.emit("error", { errorMsg: "Not authorized, no access token" });
socket.disconnect()
socket.disconnect();
}
});

Expand Down
28 changes: 16 additions & 12 deletions backend/user-service/src/controllers/authController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,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) {
Expand All @@ -173,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...");
}
Expand Down Expand Up @@ -212,7 +212,7 @@ export const oAuthAuthenticate: RequestHandler[] = [
"Access-Control-Allow-Origin": "*",
Accept: "application/json",
},
}
},
);

const resp = await response.text();
Expand All @@ -226,8 +226,8 @@ export const oAuthAuthenticate: RequestHandler[] = [
const githubUser = await user_resp.json();
const githubUserId = githubUser["id"] as number;
const user = await prisma.user.findFirst({
where: {
githubId: githubUserId
where: {
githubId: githubUserId,
},
include: {
languages: true,
Expand Down Expand Up @@ -560,7 +560,7 @@ export async function updateAccessToken(req: Request, res: Response) {
} else {
try {
const decoded = (await authenticateRefreshToken(
refreshToken
refreshToken,
)) as JwtPayload;
const userWithoutPassword = decoded.user;

Expand Down Expand Up @@ -632,7 +632,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
Expand Down Expand Up @@ -682,16 +682,20 @@ export const updateUserProfile: RequestHandler[] = [
// UPDATING BOTH TOKENS
// Fetch the latest user data from the database
const user = await prisma.user.findFirst({
where: {
id: userId
where: {
id: userId,
},
include: {
languages: true,
},
});

if (!user) {
return res.status(401).json({ message: "Had issues retrieving user while updating tokens" });
return res
.status(401)
.json({
message: "Had issues retrieving user while updating tokens",
});
}

//
Expand All @@ -703,7 +707,8 @@ export const updateUserProfile: RequestHandler[] = [
username: user.username,
} as UserWithoutPassword;
const updatedAccessToken = await generateAccessToken(userWithoutPassword);
const updatedRefreshToken = await generateRefreshToken(userWithoutPassword);
const updatedRefreshToken =
await generateRefreshToken(userWithoutPassword);

await prisma.user.update({
where: { id: userId },
Expand All @@ -725,7 +730,6 @@ export const updateUserProfile: RequestHandler[] = [
message: "User profile updated successfully",
user: updatedUser,
});

} catch (error) {
if (
error instanceof Prisma.PrismaClientKnownRequestError &&
Expand Down
4 changes: 2 additions & 2 deletions backend/user-service/src/middleware/authMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,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

Expand All @@ -52,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;
Expand Down
7 changes: 6 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,12 @@ services:
ports:
- "5672:5672"
- "15672:15672"
command: ["bash", "-c", "chmod 400 /var/lib/rabbitmq/.erlang.cookie; rabbitmq-server"]
command:
[
"bash",
"-c",
"chmod 400 /var/lib/rabbitmq/.erlang.cookie; rabbitmq-server",
]
healthcheck:
test: rabbitmq-diagnostics check_port_connectivity
interval: 1s
Expand Down
1 change: 0 additions & 1 deletion frontend/src/components/chat/ChatBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ const ChatBox: React.FC = () => {

// Join the room
useEffect(() => {

const setInitial = (roomId: string, currentUser: User): void => {
// Emit a request to join the room
socket.current?.emit('join-room', roomId, currentUser);
Expand Down
1 change: 0 additions & 1 deletion frontend/src/pages/matching/Matching.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ const Matching: React.FC = () => {
const [matchingState, setMatchingState] = useState<MatchingStateEnum>(MatchingStateEnum.NO_REQUEST);

useEffect(() => {

const newSocket = io(process.env.REACT_APP_MATCHING_SERVICE_BACKEND_URL as string, {
path: process.env.REACT_APP_MATCHING_SERVICE_PATH ?? '/socket.io/',
transports: ['websocket'],
Expand Down

0 comments on commit 11ff72c

Please sign in to comment.