@quickbiteapp/shared 1.0.18 → 1.0.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { Request, Response, NextFunction } from "express";
|
|
2
|
-
export declare const requireAuth: (req: Request, res: Response, next: NextFunction) => void;
|
|
2
|
+
export declare const requireAuth: (jwtSecret: string) => (req: Request, res: Response, next: NextFunction) => void;
|
|
@@ -6,25 +6,21 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.requireAuth = void 0;
|
|
7
7
|
const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
|
|
8
8
|
const NotAuthenticatedError_1 = require("../errors/NotAuthenticatedError");
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
catch (err) {
|
|
26
|
-
console.log(err);
|
|
27
|
-
next(new NotAuthenticatedError_1.NotAuthenticatedError());
|
|
28
|
-
}
|
|
9
|
+
const requireAuth = (jwtSecret) => {
|
|
10
|
+
return (req, res, next) => {
|
|
11
|
+
const authHeader = req.headers.authorization;
|
|
12
|
+
if (!(authHeader === null || authHeader === void 0 ? void 0 : authHeader.startsWith("Bearer "))) {
|
|
13
|
+
return next(new NotAuthenticatedError_1.NotAuthenticatedError());
|
|
14
|
+
}
|
|
15
|
+
const token = authHeader.split(" ")[1];
|
|
16
|
+
try {
|
|
17
|
+
const payload = jsonwebtoken_1.default.verify(token, jwtSecret);
|
|
18
|
+
req.user = payload;
|
|
19
|
+
next();
|
|
20
|
+
}
|
|
21
|
+
catch (_a) {
|
|
22
|
+
return next(new NotAuthenticatedError_1.NotAuthenticatedError());
|
|
23
|
+
}
|
|
24
|
+
};
|
|
29
25
|
};
|
|
30
26
|
exports.requireAuth = requireAuth;
|