Skip to content

Commit

Permalink
Skip creating SpacesClient when not needed in auth interceptor (#75706)
Browse files Browse the repository at this point in the history
Co-authored-by: Elastic Machine <[email protected]>
  • Loading branch information
kobelb and elasticmachine authored Aug 27, 2020
1 parent b98e2e4 commit bf25e16
Showing 1 changed file with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,12 @@ export function initSpacesOnPostAuthRequestInterceptor({
const isRequestingSpaceRoot = path === '/' && spaceId !== DEFAULT_SPACE_ID;
const isRequestingApplication = path.startsWith('/app');

const spacesClient = await spacesService.scopedClient(request);

// if requesting the application root, then show the Space Selector UI to allow the user to choose which space
// they wish to visit. This is done "onPostAuth" to allow the Saved Objects Client to use the request's auth credentials,
// which is not available at the time of "onRequest".
if (isRequestingKibanaRoot) {
try {
const spacesClient = await spacesService.scopedClient(request);
const spaces = await spacesClient.getAll();

if (spaces.length === 1) {
Expand Down Expand Up @@ -77,6 +76,7 @@ export function initSpacesOnPostAuthRequestInterceptor({
try {
log.debug(`Verifying access to space "${spaceId}"`);

const spacesClient = await spacesService.scopedClient(request);
space = await spacesClient.get(spaceId);
} catch (error) {
const wrappedError = wrapError(error);
Expand Down

0 comments on commit bf25e16

Please sign in to comment.