typeorm-store icon indicating copy to clipboard operation
typeorm-store copied to clipboard

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

Open araggohnxd opened this issue 2 years ago • 0 comments

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?

araggohnxd avatar Aug 24 '23 18:08 araggohnxd