Skip to content

Commit

Permalink
disableLastLoginUpdate
Browse files Browse the repository at this point in the history
  • Loading branch information
alexisvigoureux committed Nov 29, 2024
1 parent 408da3d commit 38b8feb
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
1 change: 1 addition & 0 deletions packages/core/src/config/default-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ export const defaultConfig: RuntimeVendureConfig = {
sessionCacheStrategy: new InMemorySessionCacheStrategy(),
sessionCacheTTL: 300,
requireVerification: true,
disableLastLoginUpdate: false,
verificationTokenDuration: '7d',
superadminCredentials: {
identifier: SUPER_ADMIN_USER_IDENTIFIER,
Expand Down
7 changes: 7 additions & 0 deletions packages/core/src/config/vendure-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,13 @@ export interface AuthOptions {
* @default DefaultPasswordValidationStrategy
*/
passwordValidationStrategy?: PasswordValidationStrategy;
/**
* @description
* Disable the last login update (prevent a save on user entity) when a user logs in.
* This can be useful when there is a lot of authentication in a short period of time and get lock on the user table.
* @since 3.0.7
*/
disableLastLoginUpdate?: boolean
}

/**
Expand Down
6 changes: 4 additions & 2 deletions packages/core/src/service/services/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,10 @@ export class AuthService {
if (ctx.session && ctx.session.activeOrderId) {
await this.sessionService.deleteSessionsByActiveOrderId(ctx, ctx.session.activeOrderId);
}
user.lastLogin = new Date();
await this.connection.getRepository(ctx, User).save(user, { reload: false });
if (user.roles || !this.configService.authOptions.disableLastLoginUpdate) {
user.lastLogin = new Date();
await this.connection.getRepository(ctx, User).save(user, { reload: false });
}
const session = await this.sessionService.createNewAuthenticatedSession(
ctx,
user,
Expand Down

0 comments on commit 38b8feb

Please sign in to comment.