Investigation: prevent calling `start` until auth state is resolved
Opened this issue · 1 comments
filoxo commented
I saw someone else's sample code that prevents calling start until after auth state is resolved, here: https://single-spa.slack.com/archives/C8R6U7MT7/p1630922393211100?thread_ts=1630914166.210900&cid=C8R6U7MT7
I think this is a fine enough idea to incorporate but I'd like to fully outline the benefits of doing so.
- does this prevent the applications from downloading?
- how to handle auth errors if no mfes can load without it? Perhaps a parcel UI?
filoxo commented
Copying over the code from Slack (since they'll disappear into history)
import { registerApplication, start } from "single-spa";
import {
constructApplications,
constructRoutes,
constructLayoutEngine,
} from "single-spa-layout";
import { authLib } from "./auth";
const routes = constructRoutes( ... );
const applications = constructApplications({
routes,
loadApp({ name }) {
return System.import(name);
},
});
const layoutEngine = constructLayoutEngine({ routes, applications });
applications.forEach(registerApplication);
layoutEngine.activate();
authLib.onAuthSuccess = start; // 👈
This above code isn't necessarily an example of 'the right way' but is useful for reference.