Sửa lỗi load danh sách người dùng trong quản lí
This commit is contained in:
Vendored
+2
-2
@@ -7,10 +7,10 @@ export declare class JwtStrategy extends JwtStrategy_base {
|
||||
private prisma;
|
||||
constructor(prisma: PrismaService);
|
||||
validate(payload: any): Promise<{
|
||||
id: number;
|
||||
email: string;
|
||||
passwordHash: string;
|
||||
id: number;
|
||||
name: string | null;
|
||||
passwordHash: string;
|
||||
avatar: string | null;
|
||||
createdAt: Date;
|
||||
isAdmin: boolean;
|
||||
|
||||
Vendored
+16
-5
@@ -16,6 +16,9 @@ import { PrismaService } from './prisma.service.js';
|
||||
import 'dotenv/config';
|
||||
import * as bcrypt from 'bcrypt';
|
||||
import { AdminGuard } from './admin.guard.js';
|
||||
import { JwtModule, JwtService } from '@nestjs/jwt';
|
||||
import { JwtAuthGuard } from './jwt-auth.guard.js';
|
||||
import { JwtStrategy } from './jwt.strategy.js';
|
||||
let AppController = class AppController {
|
||||
getHello() {
|
||||
return 'Travel Planning API is running!';
|
||||
@@ -31,8 +34,9 @@ AppController = __decorate([
|
||||
Controller()
|
||||
], AppController);
|
||||
let AuthController = class AuthController {
|
||||
constructor(prisma) {
|
||||
constructor(prisma, jwtService) {
|
||||
this.prisma = prisma;
|
||||
this.jwtService = jwtService;
|
||||
}
|
||||
async getStatus() {
|
||||
const userCount = await this.prisma.user.count();
|
||||
@@ -48,8 +52,9 @@ let AuthController = class AuthController {
|
||||
if (user.isBlocked) {
|
||||
throw new UnauthorizedException('Tài khoản của bạn đã bị khóa. Vui lòng liên hệ quản trị viên.');
|
||||
}
|
||||
const payload = { email: user.email, sub: user.id };
|
||||
return {
|
||||
access_token: 'simulated-jwt-token',
|
||||
access_token: this.jwtService.sign(payload),
|
||||
user: {
|
||||
id: user.id,
|
||||
email: user.email,
|
||||
@@ -94,7 +99,7 @@ __decorate([
|
||||
], AuthController.prototype, "signup", null);
|
||||
AuthController = __decorate([
|
||||
Controller('v1/auth'),
|
||||
__metadata("design:paramtypes", [PrismaService])
|
||||
__metadata("design:paramtypes", [PrismaService, JwtService])
|
||||
], AuthController);
|
||||
let TourController = class TourController {
|
||||
constructor(prisma) {
|
||||
@@ -221,15 +226,21 @@ __decorate([
|
||||
], UserController.prototype, "toggleBlock", null);
|
||||
UserController = __decorate([
|
||||
Controller('v1/users'),
|
||||
UseGuards(AdminGuard),
|
||||
UseGuards(JwtAuthGuard, AdminGuard),
|
||||
__metadata("design:paramtypes", [PrismaService])
|
||||
], UserController);
|
||||
let AppModule = class AppModule {
|
||||
};
|
||||
AppModule = __decorate([
|
||||
Module({
|
||||
imports: [
|
||||
JwtModule.register({
|
||||
secret: process.env.JWT_SECRET || 'super-secret',
|
||||
signOptions: { expiresIn: '1d' },
|
||||
}),
|
||||
],
|
||||
controllers: [AppController, AuthController, TourController, UserController],
|
||||
providers: [PrismaService],
|
||||
providers: [PrismaService, JwtStrategy],
|
||||
exports: [PrismaService]
|
||||
})
|
||||
], AppModule);
|
||||
|
||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
Vendored
+1
-1
File diff suppressed because one or more lines are too long
@@ -4,6 +4,9 @@ import { PrismaService } from './prisma.service.js';
|
||||
import 'dotenv/config';
|
||||
import * as bcrypt from 'bcrypt';
|
||||
import { AdminGuard } from './admin.guard.js';
|
||||
import { JwtModule, JwtService } from '@nestjs/jwt';
|
||||
import { JwtAuthGuard } from './jwt-auth.guard.js';
|
||||
import { JwtStrategy } from './jwt.strategy.js';
|
||||
|
||||
@Controller()
|
||||
class AppController {
|
||||
@@ -15,7 +18,7 @@ class AppController {
|
||||
|
||||
@Controller('v1/auth')
|
||||
class AuthController {
|
||||
constructor(private prisma: PrismaService) {}
|
||||
constructor(private prisma: PrismaService, private jwtService: JwtService) {}
|
||||
|
||||
@Get('status')
|
||||
async getStatus() {
|
||||
@@ -38,8 +41,10 @@ class AuthController {
|
||||
throw new UnauthorizedException('Tài khoản của bạn đã bị khóa. Vui lòng liên hệ quản trị viên.');
|
||||
}
|
||||
|
||||
const payload = { email: user.email, sub: user.id };
|
||||
|
||||
return {
|
||||
access_token: 'simulated-jwt-token',
|
||||
access_token: this.jwtService.sign(payload),
|
||||
user: {
|
||||
id: user.id,
|
||||
email: user.email,
|
||||
@@ -115,7 +120,7 @@ class TourController {
|
||||
}
|
||||
|
||||
@Controller('v1/users')
|
||||
@UseGuards(AdminGuard)
|
||||
@UseGuards(JwtAuthGuard, AdminGuard)
|
||||
class UserController {
|
||||
constructor(private prisma: PrismaService) {}
|
||||
|
||||
@@ -164,8 +169,14 @@ class UserController {
|
||||
}
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
JwtModule.register({
|
||||
secret: process.env.JWT_SECRET || 'super-secret',
|
||||
signOptions: { expiresIn: '1d' },
|
||||
}),
|
||||
],
|
||||
controllers: [AppController, AuthController, TourController, UserController],
|
||||
providers: [PrismaService],
|
||||
providers: [PrismaService, JwtStrategy],
|
||||
exports: [PrismaService]
|
||||
})
|
||||
class AppModule {}
|
||||
|
||||
Generated
+14
-2
@@ -10,6 +10,7 @@
|
||||
"dependencies": {
|
||||
"@nestjs/common": "^11.1.26",
|
||||
"@nestjs/core": "^11.1.26",
|
||||
"@nestjs/jwt": "^11.0.2",
|
||||
"@nestjs/passport": "^11.0.5",
|
||||
"@nestjs/platform-express": "^11.1.26",
|
||||
"@prisma/adapter-pg": "^7.8.0",
|
||||
@@ -1157,6 +1158,19 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/@nestjs/jwt": {
|
||||
"version": "11.0.2",
|
||||
"resolved": "https://registry.npmjs.org/@nestjs/jwt/-/jwt-11.0.2.tgz",
|
||||
"integrity": "sha512-rK8aE/3/Ma45gAWfCksAXUNbOoSOUudU0Kn3rT39htPF7wsYXtKfjALKeKKJbFrIWbLjsbqfXX5bIJNvgBugGA==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@types/jsonwebtoken": "9.0.10",
|
||||
"jsonwebtoken": "9.0.3"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@nestjs/common": "^8.0.0 || ^9.0.0 || ^10.0.0 || ^11.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@nestjs/passport": {
|
||||
"version": "11.0.5",
|
||||
"resolved": "https://registry.npmjs.org/@nestjs/passport/-/passport-11.0.5.tgz",
|
||||
@@ -2311,7 +2325,6 @@
|
||||
"version": "9.0.10",
|
||||
"resolved": "https://registry.npmjs.org/@types/jsonwebtoken/-/jsonwebtoken-9.0.10.tgz",
|
||||
"integrity": "sha512-asx5hIG9Qmf/1oStypjanR7iKTv0gXQ1Ov/jfrX6kS/EO0OFni8orbmGCn0672NHR3kXHwpAwR+B368ZGN/2rA==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@types/ms": "*",
|
||||
@@ -2332,7 +2345,6 @@
|
||||
"version": "2.1.0",
|
||||
"resolved": "https://registry.npmjs.org/@types/ms/-/ms-2.1.0.tgz",
|
||||
"integrity": "sha512-GsCCIZDE/p3i96vtEqx+7dBUGXrc7zeSK3wwPHIaRThS+9OhWIXRqzs4d6k1SVU8g91DrNRWxWUGhp5KXQb2VA==",
|
||||
"dev": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@types/node": {
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
"dependencies": {
|
||||
"@nestjs/common": "^11.1.26",
|
||||
"@nestjs/core": "^11.1.26",
|
||||
"@nestjs/jwt": "^11.0.2",
|
||||
"@nestjs/passport": "^11.0.5",
|
||||
"@nestjs/platform-express": "^11.1.26",
|
||||
"@prisma/adapter-pg": "^7.8.0",
|
||||
|
||||
Reference in New Issue
Block a user