diff --git a/src/interceptor/user.interceptor.ts b/src/interceptor/user.interceptor.ts index 15976be1..c559c9ec 100644 --- a/src/interceptor/user.interceptor.ts +++ b/src/interceptor/user.interceptor.ts @@ -23,30 +23,36 @@ export class UserInterceptor implements NestInterceptor { {}, context.active(), (span) => { + const ctxType = executionContext.getType(); + let userId: string | null = null; + if (ctxType === 'http') { + const httpReq = executionContext.switchToHttp().getRequest(); + if (httpReq.user?.id) { + userId = httpReq.user.id; + } + } else if (ctxType === 'ws') { + const client = executionContext.switchToWs().getClient(); + userId = client.data?.userId ?? null; + } return next.handle().pipe( tap((responseBody) => { - const ctxType = executionContext.getType(); - let userId: string | null = null; - if (ctxType === 'http') { + if (!userId && ctxType === 'http') { const httpReq = executionContext.switchToHttp().getRequest(); - if (httpReq.user?.id) { - userId = httpReq.user.id; - } else if ( + if ( LOGIN_URLS.includes(httpReq.url) && httpReq.method === 'POST' && responseBody?.id ) { userId = responseBody.id; } - } else if (ctxType === 'ws') { - const client = executionContext.switchToWs().getClient(); - userId = client.data.userId; } + }), + finalize(() => { if (userId) { span.setAttribute('user.id', userId); } + span.end(); }), - finalize(() => span.end()), ); }, ); diff --git a/src/namespaces/namespaces.service.ts b/src/namespaces/namespaces.service.ts index 0443ca27..37d4d5b4 100644 --- a/src/namespaces/namespaces.service.ts +++ b/src/namespaces/namespaces.service.ts @@ -273,16 +273,6 @@ export class NamespacesService { }, entityManager, ); - await this.resourcesService.createResource( - { - namespaceId, - parentId: privateRoot.id, - userId, - resourceType: ResourceType.FOLDER, - name: this.i18n.t('namespace.uncategorized'), - }, - entityManager, - ); return privateRoot.id; }