Skip to content

Commit

Permalink
feat(core): Record lastLogin date on authenticate
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelbromley committed Jun 24, 2020
1 parent a0917ac commit 39c743b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/core/src/entity/user/user.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/service/services/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down

0 comments on commit 39c743b

Please sign in to comment.