Skip to content
This repository has been archived by the owner on Apr 19, 2023. It is now read-only.

Commit

Permalink
♻️ Store parsed details in session, Change Mac OS -> macOS
Browse files Browse the repository at this point in the history
  • Loading branch information
AnandChowdhary committed Nov 15, 2020
1 parent 3c64599 commit c499a62
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/interceptors/audit-log.interceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ export class AuditLogger implements NestInterceptor {
ua.getBrowser().version ?? ''
}`.trim() || undefined,
operatingSystem:
`${ua.getOS().name ?? ''} ${
ua.getOS().version ?? ''
}`.trim() || undefined,
`${ua.getOS().name ?? ''} ${ua.getOS().version ?? ''}`
.replace('Mac OS', 'macOS')
.trim() || undefined,
};
if (request.user.id && request.user.type === 'user')
data.user = { connect: { id: request.user.id } };
Expand Down
22 changes: 21 additions & 1 deletion src/modules/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import anonymize from 'ip-anonymize';
import { authenticator } from 'otplib';
import qrcode from 'qrcode';
import randomColor from 'randomcolor';
import { UAParser } from 'ua-parser-js';
import {
COMPROMISED_PASSWORD,
EMAIL_USER_CONFLICT,
Expand Down Expand Up @@ -508,8 +509,27 @@ export class AuthService {
user: users,
): Promise<TokenResponse> {
const token = this.tokensService.generateUuid();
const ua = new UAParser(userAgent);
const location = await this.geolocationService.getLocation(ipAddress);
await this.prisma.sessions.create({
data: { token, ipAddress, userAgent, user: { connect: { id: user.id } } },
data: {
token,
ipAddress,
city: location?.city?.names?.en,
region: location?.subdivisions?.pop()?.names?.en,
timezone: location?.location?.time_zone,
countryCode: location?.country?.iso_code,
userAgent,
browser:
`${ua.getBrowser().name ?? ''} ${
ua.getBrowser().version ?? ''
}`.trim() || undefined,
operatingSystem:
`${ua.getOS().name ?? ''} ${ua.getOS().version ?? ''}`
.replace('Mac OS', 'macOS')
.trim() || undefined,
user: { connect: { id: user.id } },
},
});
return {
accessToken: await this.getAccessToken(user),
Expand Down

0 comments on commit c499a62

Please sign in to comment.