diff --git a/apps/desktop/src/app/account/account.component.html b/apps/desktop/src/app/account/account.component.html
index 7deef1274..666eae13c 100644
--- a/apps/desktop/src/app/account/account.component.html
+++ b/apps/desktop/src/app/account/account.component.html
@@ -5,7 +5,7 @@
-
+ (click)="selectAccount(account.slug, account.id)">
{{ account.title }}
{
{
provide: SDKService,
useValue: {
- nuclia: { db: { getAccounts: () => of([{ slug: 'account1', title: 'Account 1' }]) } },
+ nuclia: { db: { getAccounts: () => of([{ slug: 'account1', id: '123', title: 'Account 1' }]) } },
},
},
],
@@ -39,6 +39,6 @@ describe('SelectAccountComponent', () => {
it('should select account', () => {
const element = fixture.debugElement.nativeElement.querySelector('li');
element.click();
- expect(sync.selectAccount).toHaveBeenCalledWith('account1');
+ expect(sync.selectAccount).toHaveBeenCalledWith('account1', '123');
});
});
diff --git a/apps/desktop/src/app/account/account.component.ts b/apps/desktop/src/app/account/account.component.ts
index 6f2b54c75..5899af4f1 100644
--- a/apps/desktop/src/app/account/account.component.ts
+++ b/apps/desktop/src/app/account/account.component.ts
@@ -1,6 +1,6 @@
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { Router } from '@angular/router';
-import { ACCOUNT_KEY, SyncService } from '@nuclia/sync';
+import { SyncService } from '@nuclia/sync';
import { SDKService } from '@flaps/core';
import { catchError, of, tap } from 'rxjs';
@@ -23,15 +23,19 @@ export class SelectAccountComponent {
}),
);
- constructor(private sdk: SDKService, private sync: SyncService, private router: Router) {}
+ constructor(
+ private sdk: SDKService,
+ private sync: SyncService,
+ private router: Router,
+ ) {}
- selectAccount(account: string) {
- this.sync.selectAccount(account);
+ selectAccount(account: string, accountId: string) {
+ this.sync.selectAccount(account, accountId);
this.router.navigate(['/']);
}
logout() {
- localStorage.removeItem(ACCOUNT_KEY);
+ this.sync.cleanUpAccount();
this.sdk.nuclia.auth.logout();
this.router.navigate(['/']);
}
diff --git a/apps/desktop/src/app/base-layout/base-layout.component.ts b/apps/desktop/src/app/base-layout/base-layout.component.ts
index a4a8317e6..f17b816f0 100644
--- a/apps/desktop/src/app/base-layout/base-layout.component.ts
+++ b/apps/desktop/src/app/base-layout/base-layout.component.ts
@@ -2,7 +2,7 @@ import { ChangeDetectionStrategy, ChangeDetectorRef, Component } from '@angular/
import { Router } from '@angular/router';
import { SDKService } from '@flaps/core';
import { catchError, filter, of, switchMap, take } from 'rxjs';
-import { ACCOUNT_KEY, SyncService } from '@nuclia/sync';
+import { SyncService } from '@nuclia/sync';
@Component({
selector: 'nde-base-layout',
@@ -24,12 +24,13 @@ export class BaseLayoutComponent {
filter((yes) => yes),
take(1),
switchMap(() => {
+ const accountSlug = this.sync.getAccountSlug();
const accountId = this.sync.getAccountId();
return !accountId
? of(false)
- : this.sdk.nuclia.db.getKnowledgeBoxes(accountId).pipe(
+ : this.sdk.nuclia.db.getKnowledgeBoxes(accountSlug, accountId).pipe(
catchError(() => {
- localStorage.removeItem(ACCOUNT_KEY);
+ this.sync.cleanUpAccount();
this.sdk.nuclia.auth.logout();
this.router.navigate(['/']);
return of(false);
diff --git a/libs/sdk-core/src/lib/models.ts b/libs/sdk-core/src/lib/models.ts
index 296935921..68bd9f363 100644
--- a/libs/sdk-core/src/lib/models.ts
+++ b/libs/sdk-core/src/lib/models.ts
@@ -117,7 +117,7 @@ export interface IDb {
getAccount(): Observable;
getAccount(account?: string): Observable;
getStandaloneKbs(): Observable;
- getKnowledgeBoxes(accountSlug: string): Observable;
+ getKnowledgeBoxes(accountSlug: string, accountId?: string): Observable;
getKnowledgeBoxesForZone(accountId: string, zone: string): Observable;
getKnowledgeBox(): Observable;
getKnowledgeBox(account: string, knowledgeBoxId: string): Observable;
diff --git a/libs/sync/src/lib/main-layout/main-layout.component.ts b/libs/sync/src/lib/main-layout/main-layout.component.ts
index 7b7ba1024..472971772 100644
--- a/libs/sync/src/lib/main-layout/main-layout.component.ts
+++ b/libs/sync/src/lib/main-layout/main-layout.component.ts
@@ -30,7 +30,7 @@ export class MainLayoutComponent implements OnDestroy {
if (this.config.staticConf.client === 'dashboard') {
// Automatically select current account (In dashboard there's no account selection page like in Desktop app)
this.sdk.currentAccount.pipe(take(1)).subscribe((account) => {
- this.sync.selectAccount(account.slug);
+ this.sync.selectAccount(account.slug, account.id);
});
// Check if it's a redirect from OAuth server
diff --git a/libs/sync/src/lib/sync/destinations/nuclia-cloud.ts b/libs/sync/src/lib/sync/destinations/nuclia-cloud.ts
index 18dbc434d..441a4160a 100644
--- a/libs/sync/src/lib/sync/destinations/nuclia-cloud.ts
+++ b/libs/sync/src/lib/sync/destinations/nuclia-cloud.ts
@@ -7,7 +7,7 @@ import {
Field,
IDestinationConnector,
} from '../models';
-import { ACCOUNT_KEY } from '../sync.service';
+import { ACCOUNT_ID_KEY, ACCOUNT_KEY } from '../sync.service';
export const NucliaCloudKB: DestinationConnectorDefinition = {
id: 'nucliacloud',
@@ -59,7 +59,10 @@ class NucliaCloudKBImpl implements IDestinationConnector {
})),
),
)
- : this.nuclia.db.getKnowledgeBoxes(localStorage.getItem(ACCOUNT_KEY) || '');
+ : this.nuclia.db.getKnowledgeBoxes(
+ localStorage.getItem(ACCOUNT_KEY) || '',
+ localStorage.getItem(ACCOUNT_ID_KEY) || '',
+ );
return request.pipe(
map((kbs) => ({
id: 'kb',
diff --git a/libs/sync/src/lib/sync/new-sync.service.ts b/libs/sync/src/lib/sync/new-sync.service.ts
index 25a61cb80..08e85e0c0 100644
--- a/libs/sync/src/lib/sync/new-sync.service.ts
+++ b/libs/sync/src/lib/sync/new-sync.service.ts
@@ -350,9 +350,9 @@ export class NewSyncService {
return this.sdk.currentAccount.pipe(
take(1),
switchMap((account) =>
- this.sdk.nuclia.db.getKnowledgeBoxes(account.slug).pipe(
+ this.sdk.nuclia.db.getKnowledgeBoxes(account.slug, account.id).pipe(
map((kbs) => kbs.find((kb) => kb.id === kbId)),
- switchMap((kb) => this.sdk.nuclia.db.getKnowledgeBox(account.slug, kb?.slug || '')),
+ switchMap((kb) => this.sdk.nuclia.db.getKnowledgeBox(account.slug, kb?.id || '')),
),
),
);
diff --git a/libs/sync/src/lib/sync/sync.service.ts b/libs/sync/src/lib/sync/sync.service.ts
index 6b22f70bd..cc56a6bff 100644
--- a/libs/sync/src/lib/sync/sync.service.ts
+++ b/libs/sync/src/lib/sync/sync.service.ts
@@ -40,6 +40,7 @@ import { ConfluenceConnector } from './sources/confluence';
import { OAuthConnector } from './sources/oauth';
export const ACCOUNT_KEY = 'NUCLIA_ACCOUNT';
+export const ACCOUNT_ID_KEY = 'NUCLIA_ID_ACCOUNT';
export const LOCAL_SYNC_SERVER = 'http://localhost:5001';
export const SYNC_SERVER_KEY = 'NUCLIA_SYNC_SERVER';
@@ -284,12 +285,17 @@ export class SyncService {
return source && !(source.connectorId === 'sitemap' || (source.connectorId === 'folder' && source.permanentSync));
}
- getAccountId(): string {
+ getAccountSlug(): string {
return localStorage.getItem(ACCOUNT_KEY) || '';
}
- selectAccount(account: string) {
+ getAccountId(): string {
+ return localStorage.getItem(ACCOUNT_ID_KEY) || '';
+ }
+
+ selectAccount(account: string, accountId: string) {
localStorage.setItem(ACCOUNT_KEY, account);
+ localStorage.setItem(ACCOUNT_ID_KEY, accountId);
this.setAccount();
}
@@ -300,7 +306,10 @@ export class SyncService {
take(1),
switchMap(() =>
this.sdk.nuclia.db.getAccount(this.getAccountId()).pipe(
- tap((account) => (this.sdk.nuclia.options.accountType = account.type)),
+ tap((account) => {
+ this.sdk.nuclia.options.accountType = account.type;
+ this.sdk.nuclia.options.account = account.slug;
+ }),
switchMap((account) => this.sdk.nuclia.rest.getZoneSlug(account.zone)),
tap((zone) => (this.sdk.nuclia.options.zone = zone)),
),
@@ -341,9 +350,9 @@ export class SyncService {
return this.sdk.currentAccount.pipe(
take(1),
switchMap((account) =>
- this.sdk.nuclia.db.getKnowledgeBoxes(account.slug).pipe(
+ this.sdk.nuclia.db.getKnowledgeBoxes(account.slug, account.id).pipe(
map((kbs) => kbs.find((kb) => kb.id === kbId)),
- switchMap((kb) => this.sdk.nuclia.db.getKnowledgeBox(account.slug, kb?.slug || '')),
+ switchMap((kb) => this.sdk.nuclia.db.getKnowledgeBox(account.slug, kb?.id || '')),
),
),
);
@@ -448,8 +457,13 @@ export class SyncService {
return this.http.delete(`${this._syncServer.getValue()}/logs`);
}
- logout() {
+ cleanUpAccount() {
localStorage.removeItem(ACCOUNT_KEY);
+ localStorage.removeItem(ACCOUNT_ID_KEY);
+ }
+
+ logout() {
+ this.cleanUpAccount();
this.sdk.nuclia.auth.logout();
}
diff --git a/package.json b/package.json
index cd1bcbb7f..0734476f4 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "nuclia",
- "version": "2.7.6",
+ "version": "2.7.7",
"license": "MIT",
"author": "Nuclia.cloud",
"description": "Nuclia frontend apps and libs",