[Solved] reboot boot files after login

  • hi, i have a core boot file that depends on authenticated user and i want reboot it after login
    some simple way is refresh window after login
    any better suggestion?

  • @alphaelf you can make some sort of function in your boot file that will re-initiate whatever needs to be re-initiated.

  • @metalsadman
    my part of core boot file that needs authenticated user is:

    if (ctx.store.state.auth.authorized) {
        ctx.store.state.auth.user.modules.map(async module => {
          try {
            await require(`./../modules/${module.slug}`).default(ctx, module.config)
          } catch (e) {

    how can modify it for react response?

  • @alphaelf not that I want to interfere or something, but somehow I wonder if your solution is the right one.
    I infer, that you want to have some dynamic modules/functionalities based on app state (isAuthorized)

    If this is your scenario, then let me think, what I would do:

    1. if this is webpacked SPA/PWA app, those modules are already bundled, so there’s no security issue or a real need to LOAD them AFTER authorization. They’re already there, so I suppose, what you really want is just INIT them with a new/updated context.
    2. I assume, that those modules doesn’t need to be initialized sequentially. If that is the case instead of “await” I would use something like Promise.all([…]) instead.
    3. From the architecture point of view, those modules should be rewritten to have some kind of init function, and you can call those functions (on already loaded modules) to switch to the new context. Ideally, those modules should only depend on vuex not on your actions, because thats what for vuex is - managing global state - and isAuthorized is obviously a global state.
    4. In Vue there is a concept of “watchers”. In those modules, you could even “watch” for the changes in global vuex state, and let those modules init to default config themselfes.

  • @qyloxe ok, i use Vuex.watch() to solve it :

        (state, getters) => getters['auth/isAuth'],
        isAuth => {
          if (isAuth) {
             ctx.store.state.auth.user.modules.map(module => require(`./../modules/${module.slug}`).init(ctx, module.config))
          } else {
             ctx.store.state.auth.user.modules.map(module => require(`./../modules/${module.slug}`).terminate(ctx))

Log in to reply