📈 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!
TypeScript chartsclickhousedockergdprgoogle-analyticsmetricsmonitoringmysqlnestjsprivacyredisself-hostedselfhostedstatisticstailwindcssweb-analyticswebanalyticswebsite
fix: swetrix ce settings not updating
Blue Moused976b2bd09a9
diff --git a/backend/apps/community/src/auth/auth.service.ts b/backend/apps/community/src/auth/auth.service.tsindex 74a131434..b543111ac 100644--- a/backend/apps/community/src/auth/auth.service.ts+++ b/backend/apps/community/src/auth/auth.service.ts@@ -29,7 +29,7 @@ import {IS_REGISTRATION_DISABLED,} from '../common/constants'import { UserService } from '../user/user.service'-import { ClickhouseUser } from '../common/types'+import { User } from '../common/types'const REDIS_OIDC_SESSION_TIMEOUT = 60 * 5 // 5 minutesconst getOIDCRedisKey = (uuid: string) => `${REDIS_OIDC_SESSION_KEY}:${uuid}`@@ -111,7 +111,7 @@ export class AuthService {return randomBytes(64).toString('hex').slice(0, length)}- private async getOrCreateUserByEmail(email: string): Promise<ClickhouseUser> {+ private async getOrCreateUserByEmail(email: string) {const existingUser = await this.userService.findOne({ email })if (existingUser && existingUser.id) {@@ -157,10 +157,7 @@ export class AuthService {return assignUnassignedProjectsToUserClickhouse(userId)}- async getBasicUser(- email: string,- password: string,- ): Promise<ClickhouseUser | null> {+ async getBasicUser(email: string, password: string): Promise<User | null> {const user = await this.userService.findOne({ email })if (user && (await this.comparePassword(password, user.password))) {diff --git a/backend/apps/community/src/auth/dtos/login.dto.ts b/backend/apps/community/src/auth/dtos/login.dto.tsindex 9be0dc156..7f76f2745 100644--- a/backend/apps/community/src/auth/dtos/login.dto.ts+++ b/backend/apps/community/src/auth/dtos/login.dto.ts@@ -1,5 +1,6 @@import { ApiProperty } from '@nestjs/swagger'import { IsEmail, MinLength } from 'class-validator'+import { User } from '../../common/types'export class LoginRequestDto {@ApiProperty({@@ -34,5 +35,5 @@ export class LoginResponseDto {@ApiProperty({description: 'User entity',})- user: object+ user: Partial<User>}diff --git a/backend/apps/community/src/common/types.ts b/backend/apps/community/src/common/types.tsindex 59b1b2764..4fa3f8674 100644--- a/backend/apps/community/src/common/types.ts+++ b/backend/apps/community/src/common/types.ts@@ -1,6 +1,6 @@import { OnboardingStep } from '../user/entities/user.entity'-export interface ClickhouseUser {+export interface ClickhouseInputUser {id: stringemail: stringpassword: string@@ -12,6 +12,18 @@ export interface ClickhouseUser {apiKey: string | null}+export interface User {+ id: string+ email: string+ password: string+ timezone: string+ timeFormat: string+ showLiveVisitorsInTitle: boolean+ onboardingStep: OnboardingStep+ hasCompletedOnboarding: boolean+ apiKey: string | null+}+export interface ClickhouseProject {id: stringname: stringdiff --git a/backend/apps/community/src/user/user.controller.ts b/backend/apps/community/src/user/user.controller.tsindex 0f22cea14..df0b2fe1d 100644--- a/backend/apps/community/src/user/user.controller.ts+++ b/backend/apps/community/src/user/user.controller.ts@@ -25,7 +25,6 @@ import { RolesGuard } from '../auth/guards/roles.guard'import { CurrentUserId } from '../auth/decorators/current-user-id.decorator'import { AppLoggerService } from '../logger/logger.service'import { UserService } from './user.service'-import { ClickhouseUser } from '../common/types'import { checkRateLimit, getIPFromHeaders } from '../common/utils'@ApiTags('User')@@ -41,9 +40,7 @@ export class UserController {@Get('/me')@UseGuards(RolesGuard)@Roles(UserType.CUSTOMER, UserType.ADMIN)- async me(- @CurrentUserId() uid: string,- ): Promise<{ user: Partial<ClickhouseUser> }> {+ async me(@CurrentUserId() uid: string) {this.logger.log({ uid }, 'GET /user/me')const user = await this.userService.findOne({ id: uid })diff --git a/backend/apps/community/src/user/user.service.ts b/backend/apps/community/src/user/user.service.tsindex a10583316..fc829b09b 100644--- a/backend/apps/community/src/user/user.service.ts+++ b/backend/apps/community/src/user/user.service.ts@@ -2,7 +2,7 @@ import { Injectable } from '@nestjs/common'import { v4 as uuidv4 } from 'uuid'import _omit from 'lodash/omit'import { clickhouse } from '../common/integrations/clickhouse'-import { type ClickhouseUser } from '../common/types'+import { User, type ClickhouseInputUser } from '../common/types'import {DEFAULT_TIMEZONE,OnboardingStep,@@ -11,10 +11,8 @@ import {@Injectable()export class UserService {- async findOne(- options: Partial<ClickhouseUser>,- ): Promise<ClickhouseUser | undefined> {- const paramTypes: Record<keyof ClickhouseUser, string> = {+ async findOne(options: Partial<ClickhouseInputUser>) {+ const paramTypes: Record<keyof ClickhouseInputUser, string> = {id: 'FixedString(36)',email: 'String',password: 'String',@@ -28,7 +26,7 @@ export class UserService {const entries = Object.entries(options).filter(([key, value]) => key in paramTypes && value !== undefined,- ) as [keyof ClickhouseUser, unknown][]+ ) as [keyof ClickhouseInputUser, unknown][]const conditions: string[] = []const queryParams: Record<string, unknown> = {}@@ -49,13 +47,13 @@ export class UserService {query: `SELECT * FROM user WHERE ${where}`,query_params: queryParams,})- .then(resultSet => resultSet.json<ClickhouseUser>())+ .then(resultSet => resultSet.json<ClickhouseInputUser>())- return data[0]+ return this.formatUser(data[0])}- async update(userId: string, update: Partial<ClickhouseUser>) {- const allowedKeys: Array<keyof ClickhouseUser> = [+ async update(userId: string, update: Partial<ClickhouseInputUser>) {+ const allowedKeys: Array<keyof ClickhouseInputUser> = ['email','password','timezone',@@ -67,7 +65,7 @@ export class UserService {]const rawEntries = Object.entries(update) as [- keyof ClickhouseUser,+ keyof ClickhouseInputUser,unknown,][]const entries = rawEntries.filter(@@ -120,7 +118,7 @@ export class UserService {return this.findOne({ id: userId })}- async create(user: Pick<ClickhouseUser, 'email' | 'password'>) {+ async create(user: Pick<ClickhouseInputUser, 'email' | 'password'>) {const id = uuidv4()await clickhouse.insert({@@ -155,7 +153,19 @@ export class UserService {return Number(total) || 0}- omitSensitiveData(user: Partial<ClickhouseUser>): Partial<ClickhouseUser> {+ omitSensitiveData(user: Partial<User>): Partial<User> {return _omit(user, ['password'])}++ formatUser(user?: ClickhouseInputUser): User {+ if (!user) {+ return undefined+ }++ return {+ ...user,+ showLiveVisitorsInTitle: Boolean(user.showLiveVisitorsInTitle),+ hasCompletedOnboarding: Boolean(user.hasCompletedOnboarding),+ }+ }}