📈 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
rm isSelfhosted
Blue Mouse8a4728a075d6
diff --git a/selfhosted-src/auth/guards/roles.guard.ts b/selfhosted-src/auth/guards/roles.guard.tsindex e6c608829..5dbdcd853 100644--- a/selfhosted-src/auth/guards/roles.guard.ts+++ b/selfhosted-src/auth/guards/roles.guard.ts@@ -3,10 +3,10 @@ import { Reflector } from '@nestjs/core'import { ExtractJwt } from 'passport-jwt'import { verify } from 'jsonwebtoken'-import { UserType, generateSelfhostedUser } from 'selfhosted-src/user/entities/user.entity'+import { UserType } from 'selfhosted-src/user/entities/user.entity'import { UserService } from 'selfhosted-src/user/user.service'-import { isSelfhosted, JWT_ACCESS_TOKEN_SECRET } from 'selfhosted-src/common/constants'-import { IS_TWO_FA_NOT_REQUIRED_KEY, ROLES_KEY } from '../decorators'+import { JWT_ACCESS_TOKEN_SECRET } from 'selfhosted-src/common/constants'+import { ROLES_KEY } from '../decorators'@Injectable()export class RolesGuard implements CanActivate {@@ -21,31 +21,9 @@ export class RolesGuard implements CanActivate {context.getHandler(),)- const isTwoFaNotRequired = this.reflector.get<boolean>(- IS_TWO_FA_NOT_REQUIRED_KEY,- context.getHandler(),- )-if (!roles || roles.length === 0) return trueconst request = context.switchToHttp().getRequest()- const userFromRequest = request.user-- const user = isSelfhosted- ? generateSelfhostedUser()- : await this.userService.findUserById(userFromRequest.id)-- // this is a temp measure as well due to some fucking bug related to undefined user, will revert it when I find the cause- let hasRole- try {- hasRole = user.roles.some(role => roles.includes(role))- } catch (error) {- console.error(`[AUTH ERROR - ROLES GUARD] ${error.message}`)- console.error(user, roles)- console.error(request?.path, request?.originalUrl, request?.method)- }-- if (!hasRole) return falselet token = ''if (request.cookies.token) {@@ -55,25 +33,6 @@ export class RolesGuard implements CanActivate {token = extract(request)}- if (isSelfhosted) {- try {- const decoded: any = verify(token, JWT_ACCESS_TOKEN_SECRET)-- // If the token is not decoded, it means it's invalid- if (!decoded) {- return false- }- } catch {- return false- }-- return true- }-- if (isTwoFaNotRequired) {- return true- }-try {const decoded: any = verify(token, JWT_ACCESS_TOKEN_SECRET)@@ -81,14 +40,6 @@ export class RolesGuard implements CanActivate {if (!decoded) {return false}-- // If the user has 2FA enabled, but the token is temporary (meant to be used for 2FA routes only) then return false- if (- user.isTwoFactorAuthenticationEnabled &&- !decoded.isSecondFactorAuthenticated- ) {- return false- }} catch {return false}diff --git a/selfhosted-src/common/constants.ts b/selfhosted-src/common/constants.tsindex fb60c0988..b0b7607cd 100644--- a/selfhosted-src/common/constants.ts+++ b/selfhosted-src/common/constants.ts@@ -45,7 +45,6 @@ const clickhouse = new ClickHouse({})const { JWT_ACCESS_TOKEN_SECRET } = process.env-const isSelfhosted = Boolean(process.env.SELFHOSTED)const isNewRelicEnabled = Boolean(process.env.USE_NEW_RELIC)const isDevelopment = process.env.NODE_ENV === 'development'const PRODUCTION_ORIGIN = process.env.CLIENT_URL || 'https://swetrix.com'@@ -55,7 +54,7 @@ const SELFHOSTED_PASSWORD = process.env.PASSWORDconst UUIDV5_NAMESPACE = '912c64c1-73fd-42b6-859f-785f839a9f68'const DEFAULT_SELFHOSTED_UUID = 'deadbeef-dead-beef-dead-beefdeadbeef'-const SELFHOSTED_UUID = isSelfhosted ? getSelfhostedUUID() : ''+const SELFHOSTED_UUID = getSelfhostedUUID()const { TWO_FACTOR_AUTHENTICATION_APP_NAME } = process.env@@ -125,7 +124,6 @@ export {REDIS_LOG_CUSTOM_CACHE_KEY,REDIS_SESSION_SALT_KEY,HEARTBEAT_SID_LIFE_TIME,- isSelfhosted,UUIDV5_NAMESPACE,SELFHOSTED_EMAIL,SELFHOSTED_PASSWORD,