diff --git a/packages/core/src/entity/user/user.entity.ts b/packages/core/src/entity/user/user.entity.ts index 436babdb13..62505f420e 100644 --- a/packages/core/src/entity/user/user.entity.ts +++ b/packages/core/src/entity/user/user.entity.ts @@ -42,8 +42,8 @@ export class User extends VendureEntity implements HasCustomFields, SoftDeletabl @JoinTable() roles: Role[]; - @Column({ nullable: true }) - lastLogin: string; + @Column({ type: Date, nullable: true }) + lastLogin: Date | null; @Column(type => CustomUserFields) customFields: CustomUserFields; diff --git a/packages/core/src/service/services/auth.service.ts b/packages/core/src/service/services/auth.service.ts index 84680325f3..aa64a4994a 100644 --- a/packages/core/src/service/services/auth.service.ts +++ b/packages/core/src/service/services/auth.service.ts @@ -77,6 +77,8 @@ export class AuthService { if (ctx.session && ctx.session.activeOrder) { await this.deleteSessionsByActiveOrder(ctx.session && ctx.session.activeOrder); } + user.lastLogin = new Date(); + await this.connection.manager.save(user, { reload: false }); const session = await this.createNewAuthenticatedSession(ctx, user); const newSession = await this.connection.getRepository(AuthenticatedSession).save(session); this.eventBus.publish(new LoginEvent(ctx, user));