[英]NestJS - No metadata for "EmployeeRepository" was found with authentication
我嘗試為我的 nestjs 應用程序做一些身份驗證,但我遇到了這個錯誤,我不知道去哪里看
我的 app.module.ts
@Module({
imports: [
AgenciesModule,
ActionsModule,
AuthModule,
TypeOrmModule.forRoot({
type: 'mysql',
host: '************',
username: '*********',
password: '*********',
database: '*********',
synchronize: true,
autoLoadEntities: true,
}),
EmployeesModule,
],
})
export class AppModule {}
我的 auth.service.ts
import { EmployeeRepository } from 'src/employees/entities/employee.repository';
@Injectable()
export class AuthService {
constructor(
@InjectRepository(EmployeeRepository)
private employeeRepository: EmployeeRepository,
) {}
async validateUser(email: string, password: string): Promise<any> {
const user = await this.employeeRepository.findOne({
where: { email, password },
});
// this work with postman if I put false data
//const user = {
// email: "email",
// password: "password",
//}
if (user && user.email === email && user.password === password) {
const { password, ...result } = user;
return result;
}
return null;
}
}
我的 auth.controller.ts
@Controller('auth')
export class AuthController {
constructor(private authService: AuthService) {}
@Post('login')
async login(@Body() body) {
return this.authService.login(body.email, body.password);
}
}
我的 auth.module.ts
imports: [TypeOrmModule.forFeature([EmployeeRepository])],
controllers: [AuthController],
providers: [AuthService, JwtStrategy],
exports: [AuthService],
})
export class AuthModule {}
還有我的 employee.repository.ts
import { EntityRepository, Repository } from 'typeorm';
import { Employee } from './employee.entity';
@EntityRepository(Employee)
export class EmployeeRepository extends Repository<Employee> {}
我沒有為每個文件放置不同的導入,但如果需要我可以提供它們
我檢查了 differents 導入的所有文件名和路徑,它們都是正確的,我還更新了我的包以防萬一。
這些帖子沒有幫助: NestJS - 沒有找到“<Entity>”的元數據 使用 TypeOrm 沒有找到“User”的元數據
在 auth.module.ts 中試試這個
imports: [TypeOrmModule.forFeature([EmployeeRepository])]
像這樣改變
imports: [TypeOrmModule.forFeature([Employee])]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.