Skip to content

Commit 2b54e3e

Browse files
committed
Refactor authentication
1 parent 40535e5 commit 2b54e3e

File tree

1 file changed

+6
-20
lines changed

1 file changed

+6
-20
lines changed

middleware/auth.js

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,30 @@
11
import "dotenv/config";
22
import jwt from 'jsonwebtoken';
33

4-
export function auth(backendToken) {
5-
console.log("Backend Token", backendToken);
6-
7-
if (!backendToken) {
4+
export function auth(token) {
5+
if (!token) {
86
return false;
97
}
108

119
try {
12-
const data = jwt.verify(backendToken, process.env.APP_SECRET);
13-
console.log("Auth data", data);
14-
return data;
10+
return jwt.verify(token, process.env.APP_SECRET);
1511
} catch (err) {
16-
console.log(err);
12+
console.warn(err);
1713
return false;
1814
}
1915

2016
return true;
21-
22-
// if ("credentials" === provider) {
23-
// return true;
24-
// } else if ("keycloak" === provider) {
25-
// return true;
26-
// } else if ("livekit" === provider) {
27-
// return true;
28-
// }
29-
//
30-
// return false;
3117
}
3218

3319
export function httpAuthMiddleware(req, res, next) {
34-
if (!auth(req.query.backendToken)) {
20+
if (!auth(req.query.token)) {
3521
return res.status(401).json({ error: "Unauthorized" });
3622
}
3723
next();
3824
}
3925

4026
export function socketAuthMiddleware(socket, next) {
41-
const userData = auth(socket.handshake.query.backendToken);
27+
const userData = auth(socket.handshake.query.token);
4228
if (!userData) {
4329
return next(new Error("Unauthorized"));
4430
}

0 commit comments

Comments
 (0)