Vuepress with Okta Authentication - window is not defined during build

Viewed 604

I have been following the tutorial found here for adding authentication to my vuepress site. This all works perfectly when running in dev mode but when I try to build my application I receive the following error:

wait Rendering static HTML...
Rendering page: /error Error rendering /: false
undefined
ReferenceError: window is not defined
 at Object.module.exports.Op (node_modules/@okta/okta-vue/dist/okta- 
vue.js:1:222)
at __webpack_require__ (webpack/bootstrap:25:0)
at Module.<anonymous> (server-bundle.js:4649:16)

This is stopping me from being able to deploy my site. The issue started after I included the Okta vue sdk.

My enhanceApp.js is as follows:

import Auth from "@okta/okta-vue";
import { oktaConfig } from "./oktaConfig";

export default ({ Vue, options, router, siteData }) => {
  Vue.use(Auth, oktaConfig);
  router.beforeEach(async (to, from, next) => {
    const auth = await Vue.prototype.$auth.isAuthenticated();
    if (!auth && to.path !== "/implicit/callback/") {
      Vue.prototype.$auth.loginRedirect(to.path);
    } else {
      next();
    }
  });
};
0 Answers
Related