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!

added maxEventsCount to the userobject

Blue Mouse92b09fa10a77
diff --git a/src/auth/auth.controller.ts b/src/auth/auth.controller.ts
index de4272bfd..4ab18fa0c 100644
--- a/src/auth/auth.controller.ts
+++ b/src/auth/auth.controller.ts
@@ -50,8 +50,9 @@ export class AuthController {
email: SELFHOSTED_EMAIL,
}
} else {
- user = await this.userService.findOneWhere({ id: user_id })
- delete user.password
+ user = this.authService.processUser(
+ await this.userService.findOneWhere({ id: user_id })
+ )
}
return user
@@ -68,7 +69,9 @@ export class AuthController {
if (userLoginDTO.email !== SELFHOSTED_EMAIL || userLoginDTO.password !== SELFHOSTED_PASSWORD) {
throw new UnprocessableEntityException('Email or password is incorrect')
}
- return this.authService.login(SELFHOSTED_EMAIL)
+ return this.authService.login({
+ email: SELFHOSTED_EMAIL,
+ })
} else {
const user = await this.authService.validateUser(userLoginDTO.email, userLoginDTO.password)
return this.authService.login(user)
diff --git a/src/auth/auth.service.ts b/src/auth/auth.service.ts
index 28756d70c..1919b4e0f 100644
--- a/src/auth/auth.service.ts
+++ b/src/auth/auth.service.ts
@@ -7,6 +7,7 @@ import * as _toUpper from 'lodash/toUpper'
import * as _includes from 'lodash/includes'
import { UserService } from '../user/user.service'
+import { ACCOUNT_PLANS } from '../user/entities/user.entity'
import { AppLoggerService } from '../logger/logger.service'
import { User } from '../user/entities/user.entity'
import {
@@ -96,23 +97,38 @@ export class AuthService {
throw new UnprocessableEntityException('Email or password is incorrect')
}
- login(user: User | string): object {
+ processUser(user: User): object {
+ // @ts-ignore
+ const maxEventsCount = ACCOUNT_PLANS[user.planCode].monthlyUsageLimit || 0
+ const userData = {
+ // @ts-ignore
+ ...user,
+ password: undefined,
+ maxEventsCount,
+ }
+
+ return userData
+ }
+
+ login(user: User | object): object {
let userData = user
if (isSelfhosted) {
// @ts-ignore
userData = {
+ ...user,
id: SELFHOSTED_UUID,
}
+ } else {
+ // @ts-ignore
+ userData = this.processUser(user)
}
// @ts-ignore
- const token = sign({ user_id: user.id }, process.env.JWT_SECRET, {
+ const token = sign({ user_id: userData.id }, process.env.JWT_SECRET, {
expiresIn: JWT_LIFE_TIME,
})
- // @ts-ignore
- delete user.password
- return { access_token: token, user }
+ return { access_token: token, user: userData }
}
}