-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[sc-7748] Don't load all KBs from all accounts after login (#1100)
* [sc-7748] Don't load all KBs from all accounts after login * Fix 1 account case and prod build * Move standalone logic in the services and guards * Disable login button while logging in Login validation can take some time, and it's a bit confusing to see nothing happening right after clicking on the button when that's happening (typically for users with 1 account and 1 KB). Disabling the button while validating allows the user to understand the click was taken into account. * Better error message
- Loading branch information
1 parent
9e39089
commit b5014ee
Showing
21 changed files
with
266 additions
and
258 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export * from './auth.interceptor'; | ||
export * from './permission.guard'; | ||
export * from './root.guard'; | ||
export * from './select-account-kb.guard'; | ||
export * from './select-account.guard'; | ||
export * from './select-kb.guard'; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { ActivatedRouteSnapshot, Router } from '@angular/router'; | ||
import { inject } from '@angular/core'; | ||
import { SelectAccountKbService } from '@flaps/common'; | ||
import { catchError, of, switchMap } from 'rxjs'; | ||
import { map } from 'rxjs/operators'; | ||
|
||
export const selectAccountGuard = (route: ActivatedRouteSnapshot) => { | ||
const selectService: SelectAccountKbService = inject(SelectAccountKbService); | ||
const router: Router = inject(Router); | ||
|
||
const selectedAccount = route.children[0]?.paramMap.get('account'); | ||
|
||
if (selectedAccount) { | ||
// when loading `/select/{account}` (happens when there is only 1 account and when we reload the KB selection page) | ||
// set account in state and continue | ||
return selectService.accounts.pipe( | ||
switchMap((accounts) => { | ||
const selectAccount$ = selectService.selectAccount(selectedAccount); | ||
if (!accounts) { | ||
// on reload, we need to load accounts list | ||
return selectService.loadAccounts().pipe(switchMap(() => selectAccount$)); | ||
} else { | ||
return selectAccount$; | ||
} | ||
}), | ||
map(() => true), | ||
); | ||
} | ||
return selectService.loadAccounts().pipe( | ||
switchMap((accounts) => { | ||
// No accounts | ||
if (accounts.length === 0) { | ||
return of(router.createUrlTree(['/user/onboarding'])); | ||
} else if (accounts.length === 1) { | ||
const accountSlug = accounts[0].slug; | ||
// redirect to kb selection | ||
return selectService | ||
.selectAccount(accountSlug) | ||
.pipe(map((account) => router.createUrlTree([`/select/${accountSlug}`]))); | ||
} else { | ||
// several accounts, we continue to account selection | ||
return of(true); | ||
} | ||
}), | ||
catchError(() => { | ||
return of(router.createUrlTree(['/user/logout'])); | ||
}), | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { ActivatedRouteSnapshot, Router } from '@angular/router'; | ||
import { NavigationService, SelectAccountKbService } from '@flaps/common'; | ||
import { inject } from '@angular/core'; | ||
import { SDKService } from '@flaps/core'; | ||
import { of, switchMap } from 'rxjs'; | ||
import { map } from 'rxjs/operators'; | ||
|
||
export const selectKbGuard = (route: ActivatedRouteSnapshot) => { | ||
const selectService: SelectAccountKbService = inject(SelectAccountKbService); | ||
const navigation: NavigationService = inject(NavigationService); | ||
const sdk: SDKService = inject(SDKService); | ||
const router: Router = inject(Router); | ||
|
||
const accountSlug = route.paramMap.get('account'); | ||
|
||
return accountSlug | ||
? selectService.loadKbs(accountSlug).pipe( | ||
switchMap((kbs) => { | ||
if (kbs.length === 0) { | ||
return selectService.standalone | ||
? of(true) | ||
: sdk.currentAccount.pipe( | ||
map((account) => | ||
account.can_manage_account ? router.createUrlTree([navigation.getAccountUrl(accountSlug)]) : true, | ||
), | ||
); | ||
} else if (kbs.length === 1 && !selectService.standalone) { | ||
// if there's only one KB, and we're not in NucliaDB admin app, then we automatically select the KB | ||
return of(router.createUrlTree([navigation.getKbUrl(accountSlug, kbs[0].slug || '')])); | ||
} else { | ||
return of(true); | ||
} | ||
}), | ||
) | ||
: of(router.createUrlTree(['/select'])); | ||
}; |
Oops, something went wrong.