Skip to content
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

Investigation: prevent calling start until auth state is resolved #6

Open
filoxo opened this issue Sep 6, 2021 · 1 comment
Open

Comments

@filoxo
Copy link
Owner

filoxo commented Sep 6, 2021

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
Copy link
Owner Author

filoxo commented Nov 22, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant