-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #110 from nicolelim02/feat/communication
Verify user auth status
- Loading branch information
Showing
33 changed files
with
303 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import axios from "axios"; | ||
|
||
const USER_SERVICE_URL = | ||
process.env.USER_SERVICE_URL || "http://localhost:3001/api"; | ||
|
||
const userClient = axios.create({ | ||
baseURL: USER_SERVICE_URL, | ||
withCredentials: true, | ||
}); | ||
|
||
export const verifyToken = (token: string | undefined) => { | ||
return userClient.get("/auth/verify-token", { | ||
headers: { authorization: token }, | ||
}); | ||
}; |
19 changes: 19 additions & 0 deletions
19
backend/collab-service/src/middlewares/basicAccessControl.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { ExtendedError, Socket } from "socket.io"; | ||
import { verifyToken } from "../api/userService.ts"; | ||
|
||
export const verifyUserToken = ( | ||
socket: Socket, | ||
next: (err?: ExtendedError) => void | ||
) => { | ||
const token = | ||
socket.handshake.headers.authorization || socket.handshake.auth.token; | ||
verifyToken(token) | ||
.then(() => { | ||
console.log("Valid credentials"); | ||
next(); | ||
}) | ||
.catch((err) => { | ||
console.error(err); | ||
next(new Error("Unauthorized")); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
File renamed without changes
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
File renamed without changes
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import axios from "axios"; | ||
|
||
const USER_SERVICE_URL = | ||
process.env.USER_SERVICE_URL || "http://localhost:3001/api"; | ||
|
||
const userClient = axios.create({ | ||
baseURL: USER_SERVICE_URL, | ||
withCredentials: true, | ||
}); | ||
|
||
export const verifyToken = (token: string | undefined) => { | ||
return userClient.get("/auth/verify-token", { | ||
headers: { authorization: token }, | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
backend/communication-service/src/middlewares/basicAccessControl.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { ExtendedError, Socket } from "socket.io"; | ||
import { verifyToken } from "../api/userService"; | ||
|
||
export const verifyUserToken = ( | ||
socket: Socket, | ||
next: (err?: ExtendedError) => void | ||
) => { | ||
const token = | ||
socket.handshake.headers.authorization || socket.handshake.auth.token; | ||
verifyToken(token) | ||
.then(() => { | ||
console.log("Valid credentials"); | ||
next(); | ||
}) | ||
.catch((err) => { | ||
console.error(err); | ||
next(new Error("Unauthorized")); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
backend/matching-service/src/api/questionHistoryService.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import axios from "axios"; | ||
|
||
const QN_HISTORY_SERVICE_URL = | ||
process.env.QN_HISTORY_SERVICE_URL || | ||
"http://qn-history-service:3006/api/qnhistories"; | ||
|
||
const qnHistoryService = axios.create({ | ||
baseURL: QN_HISTORY_SERVICE_URL, | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
}); | ||
|
||
export const createQuestionHistory = ( | ||
questionId: string, | ||
title: string, | ||
submissionStatus: string, | ||
language: string, | ||
...userIds: string[] | ||
) => { | ||
const dateAttempted = new Date(); | ||
return qnHistoryService.post("/", { | ||
userIds, | ||
questionId, | ||
title, | ||
submissionStatus, | ||
language, | ||
dateAttempted, | ||
timeTaken: 0, | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import axios from "axios"; | ||
|
||
const QUESTION_SERVICE_URL = | ||
process.env.QUESTION_SERVICE_URL || | ||
"http://question-service:3000/api/questions"; | ||
|
||
const questionClient = axios.create({ | ||
baseURL: QUESTION_SERVICE_URL, | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
}); | ||
|
||
export const getRandomQuestion = (complexity: string, category: string) => { | ||
return questionClient.get("/random", { params: { complexity, category } }); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import axios from "axios"; | ||
|
||
const USER_SERVICE_URL = | ||
process.env.USER_SERVICE_URL || "http://localhost:3001/api"; | ||
|
||
const userClient = axios.create({ | ||
baseURL: USER_SERVICE_URL, | ||
withCredentials: true, | ||
}); | ||
|
||
export const verifyToken = (token: string | undefined) => { | ||
return userClient.get("/auth/verify-token", { | ||
headers: { authorization: token }, | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.