forked from Shared/esg
database migrated to POSTGRESQL
This commit is contained in:
+10
-10
@@ -35,27 +35,27 @@ export class AuthService {
|
||||
}
|
||||
|
||||
if (!user.isActive) {
|
||||
await this.auditFailedLogin(user._id.toString(), user.username, 'inactive', context);
|
||||
await this.auditFailedLogin(user.id, user.username, 'inactive', context);
|
||||
throw new AppException('ACCOUNT_INACTIVE');
|
||||
}
|
||||
|
||||
if (user.isBlocked) {
|
||||
await this.auditFailedLogin(user._id.toString(), user.username, 'blocked', context);
|
||||
await this.auditFailedLogin(user.id, user.username, 'blocked', context);
|
||||
throw new AppException('ACCOUNT_BLOCKED');
|
||||
}
|
||||
|
||||
const valid = await this.passwordService.compare(dto.password, user.password);
|
||||
if (!valid) {
|
||||
await this.auditFailedLogin(user._id.toString(), user.username, 'invalid_credentials', context);
|
||||
await this.auditFailedLogin(user.id, user.username, 'invalid_credentials', context);
|
||||
throw new AppException('INVALID_CREDENTIALS');
|
||||
}
|
||||
|
||||
const tokens = await this.issueTokens(user);
|
||||
await this.usersService.saveRefreshToken(user._id.toString(), tokens.refreshToken);
|
||||
await this.usersService.recordLogin(user._id.toString());
|
||||
await this.usersService.saveRefreshToken(user.id, tokens.refreshToken);
|
||||
await this.usersService.recordLogin(user.id);
|
||||
|
||||
await this.auditService.log(AuditEvent.LOGIN, {
|
||||
userId: user._id.toString(),
|
||||
userId: user.id,
|
||||
username: user.username,
|
||||
ip: context.ip,
|
||||
userAgent: context.userAgent,
|
||||
@@ -86,10 +86,10 @@ export class AuthService {
|
||||
}
|
||||
|
||||
const tokens = await this.issueTokens(user);
|
||||
await this.usersService.saveRefreshToken(user._id.toString(), tokens.refreshToken);
|
||||
await this.usersService.saveRefreshToken(user.id, tokens.refreshToken);
|
||||
|
||||
await this.auditService.log(AuditEvent.LOGIN, {
|
||||
userId: user._id.toString(),
|
||||
userId: user.id,
|
||||
username: user.username,
|
||||
ip: context.ip,
|
||||
userAgent: context.userAgent,
|
||||
@@ -117,13 +117,13 @@ export class AuthService {
|
||||
}
|
||||
|
||||
private async issueTokens(user: {
|
||||
_id: { toString(): string };
|
||||
id: string;
|
||||
role: JwtPayload['role'];
|
||||
clientType: JwtPayload['clientType'];
|
||||
appName: string;
|
||||
}): Promise<AuthTokensDto> {
|
||||
const payload: JwtPayload = {
|
||||
sub: user._id.toString(),
|
||||
sub: user.id,
|
||||
role: user.role,
|
||||
clientType: user.clientType,
|
||||
appName: user.appName,
|
||||
|
||||
@@ -35,7 +35,7 @@ export class JwtStrategy extends PassportStrategy(Strategy, JWT_ACCESS_STRATEGY)
|
||||
}
|
||||
|
||||
return {
|
||||
id: user._id.toString(),
|
||||
id: user.id,
|
||||
username: user.username,
|
||||
email: user.email,
|
||||
role: user.role,
|
||||
|
||||
Reference in New Issue
Block a user