45 lines
1.4 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// eslint-disable-next-line import/extensions
import { access as accessApi } from '../plugin-access/core';
// eslint-disable-next-line import/extensions
import getConfig from './helpers/getConfig';
if (!accessApi) {
throw new Error('[plugin-layout]: plugin-layout depends on plugin-accessplease install plugin-access first');
}
export const access = (memo) => {
const runtimeConfig = getConfig();
const accessIds = accessApi.getAccess();
if (!accessIds.includes('/403')) {
accessApi.setAccess(accessIds.concat('/403'));
}
if (!accessIds.includes('/404')) {
accessApi.setAccess(accessIds.concat('/404'));
}
return {
unAccessHandler({ router, to, from, next }) {
if (runtimeConfig.unAccessHandler && typeof runtimeConfig.unAccessHandler === 'function') {
return runtimeConfig.unAccessHandler({
router,
to,
from,
next,
});
}
next('/403');
},
noFoundHandler({ router, to, from, next }) {
if (runtimeConfig.noFoundHandler && typeof runtimeConfig.noFoundHandler === 'function') {
return runtimeConfig.noFoundHandler({
router,
to,
from,
next,
});
}
next('/404');
},
...memo,
};
};