Skip to content

Commit 1872338

Browse files
committed
show username on collaboration page
1 parent e353085 commit 1872338

File tree

4 files changed

+35
-76
lines changed

4 files changed

+35
-76
lines changed

collaboration-service/collaboration-service/src/middleware/auth.js

Lines changed: 0 additions & 72 deletions
This file was deleted.

feature-matching-ui/frontend/src/lib/api.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,23 @@
11
import axios from "axios";
22
import { getAccessToken } from "./auth";
33

4-
const matchBase = process.env.NEXT_PUBLIC_MATCH_BASE_URL;
4+
const matchBase =
5+
process.env.NEXT_PUBLIC_MATCH_BASE_URL ||
6+
(process.env.NODE_ENV === "development"
7+
? "http://localhost:4001"
8+
: undefined);
9+
10+
if (!matchBase) {
11+
throw new Error(
12+
"[API] NEXT_PUBLIC_MATCH_BASE_URL is not defined. Please set it in your environment configuration."
13+
);
14+
}
515

616
export const api = axios.create({
717
baseURL: matchBase,
818
timeout: 10000,
919
});
1020

11-
1221
api.interceptors.request.use((config) => {
1322
const token = getAccessToken();
1423
if (token) {

matching-service/matching-service/src/controllers/matchController.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@ export function initController(matchQueue) {
1212
export async function joinQueue(req, res) {
1313
try {
1414
const { userId, topics, difficulty } = req.body;
15+
const username = req.user?.username || req.body.username || "";
1516
if (!userId || !topics || !difficulty) {
1617
return res.status(400).json({ error: "Missing required fields" });
1718
}
1819

1920
const result = await queueRef.join({
2021
userId,
22+
username,
2123
selectedTopics: topics,
2224
selectedDifficulty: difficulty,
2325
});

matching-service/matching-service/src/services/matchQueue.js

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,12 @@ async getStatus(userId) {
6969
const isUserA = String(userId) === rawMatch.userA;
7070
const currentUserId = isUserA ? rawMatch.userA : rawMatch.userB;
7171
const partnerId = isUserA ? rawMatch.userB : rawMatch.userA;
72+
const currentUsername = isUserA
73+
? rawMatch.userAName || rawMatch.userAUsername || rawMatch.userA
74+
: rawMatch.userBName || rawMatch.userBUsername || rawMatch.userB;
75+
const partnerUsername = isUserA
76+
? rawMatch.userBName || rawMatch.userBUsername || rawMatch.userB
77+
: rawMatch.userAName || rawMatch.userAUsername || rawMatch.userA;
7278

7379
// ✅ Return fully personalized payload
7480
return {
@@ -80,7 +86,9 @@ async getStatus(userId) {
8086
createdAt: rawMatch.createdAt,
8187
sessionId,
8288
userId: currentUserId,
89+
username: currentUsername,
8390
partnerId,
91+
partnerUsername,
8492
question,
8593
},
8694
};
@@ -206,7 +214,7 @@ async getStatus(userId) {
206214
/*───────────────────────────────────────────────
207215
* Add user to queue
208216
*───────────────────────────────────────────────*/
209-
async join({ userId, selectedTopics, selectedDifficulty }) {
217+
async join({ userId, username = "", selectedTopics, selectedDifficulty }) {
210218
console.log(`[join] Attempting to join for user ${userId} with topics=${JSON.stringify(selectedTopics)}, difficulty=${selectedDifficulty}`);
211219

212220
const existing = await redisClient.hGetAll(`waiter:${userId}`);
@@ -325,6 +333,7 @@ async getStatus(userId) {
325333
const enqueueAt = nowMs();
326334
const waiter = {
327335
userId,
336+
username,
328337
selectedTopics: JSON.stringify(selectedTopics),
329338
selectedDifficulty,
330339
enqueueAt: enqueueAt.toString(),
@@ -410,16 +419,20 @@ async getStatus(userId) {
410419
/*───────────────────────────────────────────────
411420
* Finalize match
412421
*───────────────────────────────────────────────*/
413-
async _finalizePair({ a, b, topic, difficulty }) {
422+
async _finalizePair({ a, b, topic, difficulty }) {
414423
const matchId = genId();
415424
const createdAt = nowMs();
416425
const handshakeExpiresAt = createdAt + this.handshakeTtlMs;
417426

418427
// Base match metadata
428+
const userAName = a.username || "";
429+
const userBName = b.username || "";
419430
const match = {
420431
matchId,
421432
userA: a.userId,
433+
userAName,
422434
userB: b.userId,
435+
userBName,
423436
topic,
424437
difficulty,
425438
createdAt: createdAt.toString(),
@@ -452,9 +465,16 @@ async _finalizePair({ a, b, topic, difficulty }) {
452465
const res = await axios.post(`${COLLAB_SERVICE_BASE_URL}/sessions`, {
453466
userA: a.userId,
454467
userB: b.userId,
468+
userAName,
469+
userBName,
455470
topic,
456471
difficulty,
457472
questionId: match.question.id,
473+
questionTitle: match.question.title,
474+
questionDescription: match.question.description,
475+
questionDifficulty: match.question.difficulty || difficulty,
476+
questionTopic: match.question.topic || topic,
477+
question: match.question,
458478
});
459479
sessionId = res.data?.id || "";
460480
console.log(`[collab] Session created: ${sessionId}`);

0 commit comments

Comments
 (0)