@uniorganization/uni-lib 2.0.13 → 2.0.15
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.
|
@@ -11,12 +11,15 @@ const common_1 = require("@nestjs/common");
|
|
|
11
11
|
const passport_1 = require("@nestjs/passport");
|
|
12
12
|
const jwt_1 = require("@nestjs/jwt");
|
|
13
13
|
const jwt_strategy_1 = require("./jwt.strategy");
|
|
14
|
+
const typeorm_1 = require("@nestjs/typeorm");
|
|
15
|
+
const usr_entity_1 = require("../../entities/usr.entity");
|
|
14
16
|
let CommonModule = class CommonModule {
|
|
15
17
|
};
|
|
16
18
|
exports.CommonModule = CommonModule;
|
|
17
19
|
exports.CommonModule = CommonModule = __decorate([
|
|
18
20
|
(0, common_1.Module)({
|
|
19
21
|
imports: [
|
|
22
|
+
typeorm_1.TypeOrmModule.forFeature([usr_entity_1.Users]),
|
|
20
23
|
passport_1.PassportModule,
|
|
21
24
|
jwt_1.JwtModule.register({
|
|
22
25
|
secret: process.env.JWT_SECRET,
|
|
@@ -1,9 +1,23 @@
|
|
|
1
1
|
import { Strategy } from 'passport-jwt';
|
|
2
|
+
import { Users } from 'src/entities';
|
|
3
|
+
import { Repository } from 'typeorm';
|
|
2
4
|
declare const JwtStrategy_base: new (...args: any[]) => Strategy;
|
|
3
5
|
export declare class JwtStrategy extends JwtStrategy_base {
|
|
4
|
-
|
|
6
|
+
private readonly userRepository;
|
|
7
|
+
constructor(userRepository: Repository<Users>);
|
|
5
8
|
validate(payload: any): Promise<{
|
|
6
|
-
|
|
9
|
+
id: number;
|
|
10
|
+
first_name: string;
|
|
11
|
+
username: string;
|
|
12
|
+
last_name: string;
|
|
13
|
+
division: string;
|
|
14
|
+
lob: string;
|
|
15
|
+
fullName: string;
|
|
16
|
+
ntgid: string;
|
|
17
|
+
profile: string;
|
|
18
|
+
password_expired: number;
|
|
19
|
+
viewEvaluations: boolean;
|
|
20
|
+
ern: string;
|
|
7
21
|
}>;
|
|
8
22
|
}
|
|
9
23
|
export {};
|
|
@@ -8,6 +8,9 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
8
8
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
9
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
10
|
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
11
14
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
12
15
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
13
16
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -21,23 +24,33 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
21
24
|
exports.JwtStrategy = void 0;
|
|
22
25
|
const common_1 = require("@nestjs/common");
|
|
23
26
|
const passport_1 = require("@nestjs/passport");
|
|
27
|
+
const typeorm_1 = require("@nestjs/typeorm");
|
|
24
28
|
const passport_jwt_1 = require("passport-jwt");
|
|
29
|
+
const entities_1 = require("src/entities");
|
|
30
|
+
const typeorm_2 = require("typeorm");
|
|
25
31
|
let JwtStrategy = class JwtStrategy extends (0, passport_1.PassportStrategy)(passport_jwt_1.Strategy) {
|
|
26
|
-
constructor() {
|
|
32
|
+
constructor(userRepository) {
|
|
27
33
|
super({
|
|
28
34
|
jwtFromRequest: passport_jwt_1.ExtractJwt.fromAuthHeaderAsBearerToken(),
|
|
29
35
|
ignoreExpiration: JSON.parse(process.env.JWT_IGNORE_EXPIRATION) || false,
|
|
30
36
|
secretOrKey: process.env.JWT_SECRET,
|
|
31
37
|
});
|
|
38
|
+
this.userRepository = userRepository;
|
|
32
39
|
}
|
|
33
40
|
validate(payload) {
|
|
34
41
|
return __awaiter(this, void 0, void 0, function* () {
|
|
35
|
-
|
|
42
|
+
const user = yield this.userRepository.findOne(payload.user.id);
|
|
43
|
+
if (!user) {
|
|
44
|
+
throw new common_1.UnauthorizedException('User not found');
|
|
45
|
+
}
|
|
46
|
+
const { id, first_name, username, last_name, division, lob, fullName, ntgid, profile, password_expired, viewEvaluations, ern } = user;
|
|
47
|
+
return { id, first_name, username, last_name, division, lob, fullName, ntgid, profile, password_expired, viewEvaluations, ern };
|
|
36
48
|
});
|
|
37
49
|
}
|
|
38
50
|
};
|
|
39
51
|
exports.JwtStrategy = JwtStrategy;
|
|
40
52
|
exports.JwtStrategy = JwtStrategy = __decorate([
|
|
41
53
|
(0, common_1.Injectable)(),
|
|
42
|
-
|
|
54
|
+
__param(0, (0, typeorm_1.InjectRepository)(entities_1.Users)),
|
|
55
|
+
__metadata("design:paramtypes", [typeorm_2.Repository])
|
|
43
56
|
], JwtStrategy);
|