Skip to content

📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!

(improvments) recieve login checkbox

Maksim Mrugb1b7d6786c4e
diff --git a/apps/production/src/auth/auth.controller.ts b/apps/production/src/auth/auth.controller.ts
index 63ea66f77..12aa18e7c 100644
--- a/apps/production/src/auth/auth.controller.ts
+++ b/apps/production/src/auth/auth.controller.ts
@@ -151,7 +151,9 @@ export class AuthController {
!user.isTwoFactorAuthenticationEnabled,
)
- await this.authService.sendTelegramNotification(user.id, headers, ip)
+ if (user.isReceiveLoginAlerts) {
+ await this.authService.sendTelegramNotification(user.id, headers, ip)
+ }
if (user.isTwoFactorAuthenticationEnabled) {
user = _pick(user, ['isTwoFactorAuthenticationEnabled', 'email'])
diff --git a/apps/production/src/user/entities/user.entity.ts b/apps/production/src/user/entities/user.entity.ts
index 484e62e8f..421aff5ef 100644
--- a/apps/production/src/user/entities/user.entity.ts
+++ b/apps/production/src/user/entities/user.entity.ts
@@ -275,6 +275,12 @@ export class User {
})
isTelegramChatIdConfirmed: boolean
+ @Column({
+ type: 'boolean',
+ default: false,
+ })
+ isReceiveLoginAlerts: boolean
+
@Column({
type: 'enum',
enum: TimeFormat,
diff --git a/apps/production/src/user/user.controller.ts b/apps/production/src/user/user.controller.ts
index 986b4f236..dd93c40cc 100644
--- a/apps/production/src/user/user.controller.ts
+++ b/apps/production/src/user/user.controller.ts
@@ -176,6 +176,21 @@ export class UserController {
return null
}
+ @Post('/recieve-login-notification')
+ @UseGuards(JwtAccessTokenGuard, RolesGuard)
+ @Roles(UserType.CUSTOMER, UserType.ADMIN)
+ async recieveLoginNotification(
+ @CurrentUserId() userId: string,
+ @Body('recieveLoginNotification') recieveLoginNotification: boolean,
+ ): Promise<User> {
+ this.logger.log(
+ { userId, recieveLoginNotification },
+ 'POST /user/recieve-login-notification',
+ )
+
+ return this.userService.update(userId, { recieveLoginNotification })
+ }
+
@Post('/api-key')
@UseGuards(JwtAccessTokenGuard, RolesGuard)
@Roles(UserType.CUSTOMER, UserType.ADMIN)