Mrtenz / typeorm-store

A TypeORM-based store for express-session.
MIT License
16 stars 12 forks source link

Is there a way to add custom metadata to the session table? #34

Open araggohnxd opened 1 year ago

araggohnxd commented 1 year ago

Lets say I want to associate a user ID with my session entity, so I can easily retrieve all sessions from a user for a feature such as "logout from all devices".

Something like this:

@Entity()
export class Session extends BaseEntity implements SessionEntity {
  @Index()
  @Column('bigint')
  expiresAt: number;

  @PrimaryColumn()
  id: string;

  @Column('json')
  data: string;

  @ManyToOne(() => User, (user) => user.sessions)
  @JoinColumn({name: 'userId'})
  user: User;
}

How can I make it so, whenever a new session is created, this column is populated with the associated user ID?