Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion frontend/src/modules/auth/services/auth.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Auth0Service } from '@/modules/auth/services/auth0.service';
import config from '@/config';

class AuthServiceClass {
setToken(token: string) {
Expand All @@ -14,7 +15,7 @@ class AuthServiceClass {
}

getTenantId() {
return localStorage.getItem('currentTenant');
return localStorage.getItem('currentTenant') || config.lf.tenantId;
}

logout() {
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/modules/lf/segments/lf-segments-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ export class LfService {
static async queryProjectGroups(body) {
const tenantId = AuthService.getTenantId();

if (!tenantId) {
return { rows: [], count: 0 };
}

Comment on lines +54 to +57
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

🛠️ Refactor suggestion

Consider consistent error handling across all tenant-dependent methods

The null check for tenantId is currently only implemented in queryProjectGroups(), but all other methods in this service also depend on a valid tenant ID. Similar protection should be added to all methods to prevent potential API errors.

Here are the methods that need the same protection:

  • findSegment()
  • listSegmentsByIds()
  • updateSegment()
  • createProjectGroup()
  • queryProjects()
  • createProject()
  • createSubProject()
  • getUser()
  • fetchAuditLogs()

The original suggestion to extract this check into a utility function is valid and would help maintain consistency across all these methods.

🔗 Analysis chain

Consider consistent error handling across all tenant-dependent methods

While this defensive check prevents the initial project query failure, similar protection might be needed in other methods that depend on tenant ID.

Consider extracting this check into a utility function and applying it consistently:

+ static handleMissingTenant() {
+   if (!AuthService.getTenantId()) {
+     console.warn('Operation skipped - no tenant ID available');
+     return { rows: [], count: 0 };
+   }
+   return null;
+ }

  static async queryProjectGroups(body) {
    const tenantId = AuthService.getTenantId();
-   if (!tenantId) {
-     return { rows: [], count: 0 };
-   }
+   const emptyResult = LfService.handleMissingTenant();
+   if (emptyResult) return emptyResult;

Let's check other methods that might need similar protection:


The previous search revealed many usages of getTenantId() across the codebase, but we need to focus specifically on the lf-segments-service.js file to see which methods need similar protection. Let's analyze the methods in this file to make a more targeted recommendation.


Let's try using ripgrep instead to analyze the methods in lf-segments-service.js that use getTenantId() and see their surrounding context to determine which ones need similar null checks.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Find all methods that use getTenantId
ast-grep --pattern 'AuthService.getTenantId()' -A 5

Length of output: 66080


Script:

#!/bin/bash
# Find all methods in lf-segments-service.js that use getTenantId() and check if they have null checks
ast-grep --pattern 'const tenantId = AuthService.getTenantId()' -f frontend/src/modules/lf/segments/lf-segments-service.js -A 5

Length of output: 307


Script:

#!/bin/bash
# Find all methods in lf-segments-service.js that use getTenantId()
rg "const tenantId = AuthService.getTenantId\(\)" frontend/src/modules/lf/segments/lf-segments-service.js -A 5 -B 2

Length of output: 2238

const response = await authAxios.post(
`/tenant/${tenantId}/segment/projectGroup/query`,
{
Expand Down
Loading