#getRepository is deprecated what do we use instead?
24 messages · Page 1 of 1 (latest)
Instead of getRepository as a direct method, get the repository from the DI container. cosnt sessionRepository = app.get(getRepositoryToken(Session), { strict: false })
thank you so much @stray pier
can u also help how can I get over this ?
[Nest] 8576 - 17.10.2022 19:26:23 ERROR [ExceptionHandler] Nest could not find SessionRepository element (this provider does not exist in the current context)
Error: Nest could not find SessionRepository element (this provider does not exist in the current context)
my main.ts
async function bootstrap() {
const app = await NestFactory.create(AppModule);
const sessionRepository = app.get(getRepositoryToken(Session), {
strict: false,
});
app.use(
session({
secret: process.env.SESSION_SECRET,
resave: false,
proxy: true,
saveUninitialized: false,
cookie: {
httpOnly: true,
maxAge: parseInt(process.env.SESSION_MAX_AGE),
secure: process.env.NODE_ENV === 'production' ? true : false,
sameSite: process.env.NODE_ENV === 'production' ? 'none' : 'lax',
},
store: new TypeormStore({
cleanupLimit: 2,
limitSubquery: false,
ttl: 86400,
}).connect(sessionRepository),
}),
);
app.use(passport.initialize());
app.use(passport.session());
await app.listen(8080);
}
bootstrap();
my app module
import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { UserModule } from './user/user.module';
import { RoleModule } from './role/role.module';
// import { RoleController } from './role/role.controller';
import { TaskModule } from './task/task.module';
import { CategoryModule } from './category/category.module';
import { CommentModule } from './comment/comment.module';
import { ReviewModule } from './review/review.module';
import { TypeOrmModule } from '@nestjs/typeorm';
import { ConfigModule } from '@nestjs/config';
import { SessionService } from './session/session.service';
@Module({
imports: [
TypeOrmModule.forRoot({
type: 'postgres',
host: 'localhost',
port: 5432,
username: 'postgres',
password: '.....',
database: 'task_management',
autoLoadEntities: true,
synchronize: true,
}),
ConfigModule.forRoot(),
UserModule,
RoleModule,
TaskModule,
CategoryModule,
CommentModule,
ReviewModule,
],
controllers: [AppController],
providers: [AppService],
})
export class AppModule {}
Do you have a TypeOrmModule.forFeature([Session]) anywhere?
yes
inside the session.module.ts
but I created that randomly is that making a problem?
Do you add SessionModule to AppModule or to a module that AppModule imports?
@Module({
imports: [TypeOrmModule.forFeature([Session]), forwardRef(() => AppModule)],
controllers: [],
providers: [SessionService],
exports: [SessionService],
})
export class SessionModule {}
I made something like tihs
i'm very new to the module
Why is it forwardRefing the AppModule?
thank you. it fixed the errors but my connect-type orm store doesn't add my session to the sessions table, any idea what could it be?
No clue to be honest. I'd need a reproduction. I don't usually use TypeORM or this library
u use prisma?