NestJS Tutorial #15 - Session Stores

Поділитися
Вставка
  • Опубліковано 25 лис 2024

КОМЕНТАРІ • 30

  • @anantjain811
    @anantjain811 2 роки тому +21

    Error: "getRepository is deprecated on version 0.3.0 and up" can be resolved by making the following change in "main.ts" file:
    const sessionRepository = app.get(DataSource).getRepository(SessionEntity);
    Here, "DataSource" needs to be imported from typeorm package :)

    • @mwambalision5174
      @mwambalision5174 Рік тому

      Thought you were just a life saver. then i saw the deathnote profile 💥 you're on GodMode

    • @vitaliyhusti
      @vitaliyhusti Рік тому

      Thx man!

    • @msrini
      @msrini Рік тому

      I was looking for this solution for the past 2 days. Thanks a lot

    • @bex3911
      @bex3911 Рік тому

      Thx!

    • @azeezabdulsalam2117
      @azeezabdulsalam2117 Рік тому

      I've been having this issue for some hours now and now i stumbled on this fix. Thanks man

  • @AliAliOxenFree
    @AliAliOxenFree Рік тому +4

    SessionsEntity worked perfectly when i did it like so:
    @Column({ type: 'text' })
    json: string;
    @DeleteDateColumn({ type: 'timestamp', nullable: true })
    destroyedAt?: Date;
    another masterful lesson from AnsonTheDev! thanks so much for this series

  • @19jnz08
    @19jnz08 2 роки тому +1

    Great job!
    I've started learning NestJs and this is so helpful.

  • @cristhiamhenao7660
    @cristhiamhenao7660 Рік тому +1

    For the cleanupLimit, I was able to fix it by setting limitSubquery to false

  • @mirzazplayz_rblx
    @mirzazplayz_rblx 3 роки тому

    Dang bro watching you after so long time still same hype

  • @sidaliassoul408
    @sidaliassoul408 2 роки тому

    Great video !! Can you make a video on how we get the session data directly from the memory store.

  • @noname13345
    @noname13345 6 місяців тому

    Can we 'renew' or give the user a new session when their old session expires without asking them to login.

  • @AfifAlfiano
    @AfifAlfiano Рік тому +1

    I wanna ask something, why we need to @Inject service on each controller? is it problem just instance the service without inject it?

    • @bugraotken
      @bugraotken 11 місяців тому

      While Anson was writing the code with provide and useClass, I was not following this way so when I tried the code without Inject, it didn't work and I was very surprised. Can someone explain please?

    • @noname13345
      @noname13345 6 місяців тому

      @@bugraotken I have the code working without inject, its just another way of doing dependency injections.

  • @wilschoy78
    @wilschoy78 2 роки тому +2

    i found an error getRepository is deprecated on version 0.3.0 and up

    • @b2omker
      @b2omker 2 роки тому +6

      Hi, i just faced the same problem.
      First, i use @freshgiammi/connect-typeorm instead of the one in the video to avoid typeorm dependancies problems..
      After that, in the app.module.ts, i change the constructor of the AppModule class and create a method to return Datasource:
      export class AppModule {
      constructor(private dataSource: DataSource) {}
      getDataSource() {
      return this.dataSource;
      }
      }
      Now in the main.ts file, i add:
      const sessionRepository = app
      .get(AppModule)
      .getDataSource()
      .getRepository(SessionEntity);
      In the app.use for the sessions settings , i put:
      store: new TypeormStore({
      cleanupLimit: 2,
      limitSubquery: false,
      ttl: 86400,
      }).connect(sessionRepository)
      And it seems to work.. I don't really know if this is a good way to do it but it's a patch waiting for Anson answer :p

    • @wilschoy78
      @wilschoy78 2 роки тому +1

      @@b2omker thank you so much for sharing this idea it helps a lot...yeah waiting for Anson's answer too...

  • @ziggys.9768
    @ziggys.9768 2 роки тому

    Hi! Can you explain in a video why getRepository is deprecated and how is the best way to solve it

    • @insomnia6961
      @insomnia6961 Рік тому

      Hi!
      I solved it that way:
      in your app module you define the datasource in your imports array:
      TypeOrmModule.forRoot({
      type: 'postgres',
      host: process.env.POSTGRES_HOST,
      port: +process.env.POSTGRES_PORT,
      username: process.env.POSTGRES_USER,
      password: process.env.POSTGRES_PASSWORD,
      database: process.env.POSTGRES_DATABASE,
      autoLoadEntities: true,
      logging: false,
      // entities:[
      // 'dist/**/*.entity.js'
      // ],
      synchronize: true,
      migrations: [
      'dist/database/migrations/*.js'
      ]
      }),
      then you can inject the datasource with app.get into your main.ts:
      const sessionRepository = app.get(DataSource).getRepository(Session)
      (note, in my case it is "Session" not "SessionEntity" but it's the same model behind)

  • @shyraccoon4322
    @shyraccoon4322 Рік тому

    thank you so much

  • @nikkofebika8707
    @nikkofebika8707 Рік тому

    i confused see this video playlist

  • @abdullahchaniago1081
    @abdullahchaniago1081 11 місяців тому

    import {ISession} from 'connect-typeorm'
    import { Column, Index, PrimaryColumn,Entity, DeleteDateColumn} from 'typeorm'
    @Entity('sessions')
    export class SessionEntity implements ISession{
    @Index()
    @Column('bigint')
    expiredAt= Date.now()
    @PrimaryColumn('varchar', {length:255})
    id=''
    @Column('text')
    json: string=''
    @DeleteDateColumn()
    destroyedAt?: Date;
    }
    now the ISession need @DeleteDateColumn. what should i fill it? only Date?

  • @виртуоз_ру
    @виртуоз_ру Рік тому

    👍