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 route to get "me"

Yevhenii Kulisidicb1400cc806c
diff --git a/src/user/user.controller.ts b/src/user/user.controller.ts
index 3ca74d3c2..6789d8ac8 100644
--- a/src/user/user.controller.ts
+++ b/src/user/user.controller.ts
@@ -40,7 +40,13 @@ import {
} from './entities/user.entity'
import { Roles } from '../auth/decorators/roles.decorator'
import { Pagination } from '../common/pagination/pagination'
-import { GDPR_EXPORT_TIMEFRAME, clickhouse } from '../common/constants'
+import {
+ GDPR_EXPORT_TIMEFRAME,
+ clickhouse,
+ isSelfhosted,
+ SELFHOSTED_UUID,
+ SELFHOSTED_EMAIL,
+} from '../common/constants'
import { RolesGuard } from '../auth/guards/roles.guard'
import { SelfhostedGuard } from '../common/guards/selfhosted.guard'
import { UpdateUserProfileDTO } from './dto/update-user.dto'
@@ -76,6 +82,35 @@ export class UserController {
@InjectBot() private bot: Telegraf<TelegrafContext>,
) {}
+ @Get('/me')
+ @UseGuards(RolesGuard)
+ @Roles(UserType.CUSTOMER, UserType.ADMIN)
+ async me(@CurrentUserId() user_id: string): Promise<User> {
+ this.logger.log({ user_id }, 'GET /auth/me')
+ let user
+
+ if (isSelfhosted) {
+ user = {
+ id: SELFHOSTED_UUID,
+ email: SELFHOSTED_EMAIL,
+ }
+ } else {
+ const sharedProjects = await this.projectService.findShare({
+ where: {
+ user: user_id,
+ },
+ relations: ['project'],
+ })
+ user = this.userService.processUser(
+ await this.userService.findOneWhere({ id: user_id }),
+ )
+
+ user.sharedProjects = sharedProjects
+ }
+
+ return this.userService.omitSensitiveData(user)
+ }
+
@Get('/')
@ApiQuery({ name: 'take', required: false })
@ApiQuery({ name: 'skip', required: false })
diff --git a/src/user/user.service.ts b/src/user/user.service.ts
index 8df3251b0..ebe61b69e 100644
--- a/src/user/user.service.ts
+++ b/src/user/user.service.ts
@@ -133,6 +133,21 @@ export class UserService {
}
}
+ processUser(user: User): object {
+ // @ts-ignore
+ const maxEventsCount = ACCOUNT_PLANS[user?.planCode]?.monthlyUsageLimit || 0
+ const userData = {
+ // @ts-ignore
+ ...user,
+ password: undefined,
+ twoFactorRecoveryCode: undefined,
+ twoFactorAuthenticationSecret: undefined,
+ maxEventsCount,
+ }
+
+ return userData
+ }
+
search(query: string): Promise<User[]> {
return this.usersRepository
.createQueryBuilder('user')