我一直在关注here的教程,该教程用于向vuepress网站添加身份验证。在开发人员模式下运行时,这一切都可以正常工作,但是当我尝试构建应用程序时,出现以下错误:
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)
这使我无法部署网站。在我加入Okta vue sdk之后,问题就开始了。
我的EnhanceApp.js如下:
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();
}
});
};