nameczz 4 anni fa
parent
commit
d9482e750d

+ 2 - 2
server/src/auth/auth.service.spec.ts

@@ -34,7 +34,7 @@ describe('AuthService', () => {
   });
 
   it('validateUser shoule be true', async () => {
-    const res = await service.validateUser('milvus', 'milvus-em');
+    const res = await service.validateUser('milvus', 'milvus-admin');
     expect(res).toEqual({ userId: 1, username: 'milvus' });
   });
 
@@ -48,7 +48,7 @@ describe('AuthService', () => {
     expect(res).toHaveProperty('access_token');
   });
 
-  it('local validate', async function() {
+  it('local validate', async () => {
     try {
       await localStrategy.validate('notexist', 'asd');
     } catch (e) {

+ 3 - 1
server/src/milvus/milvus.controller.ts

@@ -2,6 +2,7 @@ import {
   Body,
   Controller,
   Post,
+  UseGuards,
   UseInterceptors,
   UsePipes,
 } from '@nestjs/common';
@@ -9,11 +10,12 @@ import { ErrorInterceptor } from 'src/interceptors';
 import { ValidationPipe } from 'src/pipe/validation.pipe';
 import { ConnectMilvus } from './dto';
 import { MilvusService } from './milvus.service';
-
+import { AuthGuard } from '@nestjs/passport';
 @Controller('milvus')
 export class MilvusController {
   constructor(private milvusService: MilvusService) {}
 
+  @UseGuards(AuthGuard('jwt'))
   @Post('connect')
   @UsePipes(new ValidationPipe())
   @UseInterceptors(new ErrorInterceptor())