-
Notifications
You must be signed in to change notification settings - Fork 257
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handle harvester loading in a route guard to better handle the unauthenticated method. #11373
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import dynamicPluginLoader from '@shell/pkg/dynamic-plugin-loader'; | ||
import { routeRequiresAuthentication } from '@shell/utils/router'; | ||
|
||
export function install(router, context) { | ||
router.beforeEach((to, from, next) => runtimeExtensionRoute(to, from, next, context)); | ||
} | ||
|
||
export async function runtimeExtensionRoute(to, from, next, { store }) { | ||
if (!routeRequiresAuthentication(to) || to.name !== '404') { | ||
return next(); | ||
} | ||
|
||
try { | ||
// Handle the loading of dynamic plugins (Harvester) because we only want to attempt to load those plugins and routes if we first couldn't find a page. | ||
// We should probably get rid of this concept entirely and just load plugins at the start. | ||
await store.dispatch('loadManagement'); | ||
const newLocation = await dynamicPluginLoader.check({ route: { path: window.location.pathname }, store }); | ||
|
||
// If we have a new location, double check that it's actually valid | ||
const resolvedRoute = newLocation ? store.app.router.resolve(newLocation) : null; | ||
|
||
if (resolvedRoute?.route.matched.length) { | ||
// Note - don't use `redirect` or `store.app.route` (breaks feature by failing to run middleware in default layout) | ||
return next(newLocation); | ||
} | ||
} catch (e) { | ||
console.error('Failed to load harvester', e); // eslint-disable-line no-console | ||
} | ||
|
||
next(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -484,4 +484,12 @@ export default [ | |
component: () => interopDefault(import('@shell/pages/c/_cluster/_product/_resource/_namespace/_id.vue')), | ||
name: 'c-cluster-product-resource-namespace-id' | ||
}] | ||
}]; | ||
}, | ||
{ | ||
path: '*', | ||
name: '404', | ||
component: () => interopDefault(import('@shell/pages/404.vue')), | ||
meta: { requiresAuthentication: true }, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We specifically needed this component so we could make sure authentication would be run on 404s. |
||
}, | ||
|
||
]; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,6 @@ import { updatePageTitle } from '@shell/utils/title'; | |
import { getVendor } from '@shell/config/private-label'; | ||
import middleware from '@shell/config/middleware.js'; | ||
import { withQuery } from 'ufo'; | ||
import dynamicPluginLoader from '@shell/pkg/dynamic-plugin-loader'; | ||
|
||
// Global variable used on mount, updated on route change and used in the render function | ||
let app; | ||
|
@@ -199,26 +198,6 @@ async function render(to, from, next) { | |
const matches = []; | ||
const Components = getMatchedComponents(to, matches); | ||
|
||
// If no Components matched, generate 404 | ||
if (!Components.length) { | ||
Comment on lines
-202
to
-203
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will no longer ever be true because our 404 page will match if nothing else will. |
||
// Handle the loading of dynamic plugins (Harvester) because we only want to attempt to load those plugins and routes if we first couldn't find a page. | ||
// We should probably get rid of this concept entirely and just load plugins at the start. | ||
await app.context.store.dispatch('loadManagement'); | ||
const newLocation = await dynamicPluginLoader.check({ route: { path: window.location.pathname }, store: app.context.store }); | ||
|
||
// If we have a new location, double check that it's actually valid | ||
const resolvedRoute = newLocation?.path ? app.context.store.app.router.resolve({ path: newLocation.path.replace(/^\/{0,1}dashboard/, '') }) : null; | ||
|
||
if (resolvedRoute?.route.matched.length) { | ||
// Note - don't use `redirect` or `store.app.route` (breaks feature by failing to run middleware in default layout) | ||
return next(resolvedRoute.resolved.path); | ||
} | ||
|
||
errorRedirect(this, new Error('404: This page could not be found')); | ||
|
||
return next(); | ||
} | ||
|
||
try { | ||
// Call middleware | ||
await callMiddleware.call(this, Components, app.context); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<script> | ||
import Brand from '@shell/mixins/brand'; | ||
|
||
export default { | ||
mixins: [Brand], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need this to reduce the flicker in dark mode. |
||
beforeMount() { | ||
this.$store.commit('setError', { error: new Error('404: This page could not be found') }); | ||
this.$router.replace('/fail-whale'); | ||
} | ||
Comment on lines
+6
to
+9
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If route guards don't redirect us we should go to failwhale with the error message we used to emit in the |
||
}; | ||
</script> | ||
|
||
<template> | ||
<div class="dashboard-root" /> | ||
</template> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes me nervous, we're calling this before some of the normal setup stuff in the auth middleware. It's quite dependent on the order the nav guards run as well, more in PR review comment