@sendhome/common 1.0.58 → 1.0.59
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,14 @@
|
|
|
1
1
|
import { Request, Response, NextFunction } from 'express';
|
|
2
|
+
interface UserPayload {
|
|
3
|
+
id: string;
|
|
4
|
+
email: string;
|
|
5
|
+
}
|
|
6
|
+
declare global {
|
|
7
|
+
namespace Express {
|
|
8
|
+
interface Request {
|
|
9
|
+
currentUser?: UserPayload;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
}
|
|
2
13
|
export declare const requireAuth: (req: Request, res: Response, next: NextFunction) => void;
|
|
14
|
+
export {};
|
|
@@ -1,11 +1,30 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.requireAuth = void 0;
|
|
7
|
+
const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
|
|
4
8
|
const not_authorized_error_1 = require("../errors/not-authorized-error");
|
|
5
9
|
const requireAuth = (req, res, next) => {
|
|
6
|
-
|
|
10
|
+
let token;
|
|
11
|
+
if (req.headers.authorization &&
|
|
12
|
+
req.headers.authorization.startsWith("Bearer")) {
|
|
13
|
+
// Set token from Bearer token in header
|
|
14
|
+
token = req.headers.authorization.split(" ")[1];
|
|
15
|
+
}
|
|
16
|
+
// Make sure token exists
|
|
17
|
+
if (!token) {
|
|
7
18
|
throw new not_authorized_error_1.NotAuthorizedError();
|
|
8
19
|
}
|
|
20
|
+
try {
|
|
21
|
+
const payload = jsonwebtoken_1.default.verify(token, "EDWIN"
|
|
22
|
+
// process.env.JWT_KEY!
|
|
23
|
+
);
|
|
24
|
+
req.currentUser = payload;
|
|
25
|
+
console.log("req.currentUser", req.currentUser);
|
|
26
|
+
}
|
|
27
|
+
catch (err) { }
|
|
9
28
|
next();
|
|
10
29
|
};
|
|
11
30
|
exports.requireAuth = requireAuth;
|
package/package.json
CHANGED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { Request, Response, NextFunction } from 'express';
|
|
2
|
-
interface UserPayload {
|
|
3
|
-
id: string;
|
|
4
|
-
email: string;
|
|
5
|
-
}
|
|
6
|
-
declare global {
|
|
7
|
-
namespace Express {
|
|
8
|
-
interface Request {
|
|
9
|
-
currentUser?: UserPayload;
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
export declare const requireAuth: (req: Request, res: Response, next: NextFunction) => void;
|
|
14
|
-
export {};
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.requireAuth = void 0;
|
|
7
|
-
const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
|
|
8
|
-
const not_authorized_error_1 = require("../errors/not-authorized-error");
|
|
9
|
-
const requireAuth = (req, res, next) => {
|
|
10
|
-
let token;
|
|
11
|
-
if (req.headers.authorization &&
|
|
12
|
-
req.headers.authorization.startsWith("Bearer")) {
|
|
13
|
-
// Set token from Bearer token in header
|
|
14
|
-
token = req.headers.authorization.split(" ")[1];
|
|
15
|
-
}
|
|
16
|
-
// Make sure token exists
|
|
17
|
-
if (!token) {
|
|
18
|
-
throw new not_authorized_error_1.NotAuthorizedError();
|
|
19
|
-
}
|
|
20
|
-
try {
|
|
21
|
-
const payload = jsonwebtoken_1.default.verify(token, "EDWIN"
|
|
22
|
-
// process.env.JWT_KEY!
|
|
23
|
-
);
|
|
24
|
-
req.currentUser = payload;
|
|
25
|
-
console.log("req.currentUser", req.currentUser);
|
|
26
|
-
}
|
|
27
|
-
catch (err) { }
|
|
28
|
-
next();
|
|
29
|
-
};
|
|
30
|
-
exports.requireAuth = requireAuth;
|