-
Notifications
You must be signed in to change notification settings - Fork 25
Description
Describe the bug
Hi,
I am working on developing an new application using Vue3 + Vite + Okta Vue and Codebuild.
After configuring everything. When I am running npm start I am able to open application in my local machine - Okta is generating Access Token.
But the problem is when I am deploy the app in dev codebuild then It is not generating Access Token.
Even In the local storage access token is getting stored. Attaching respective screenshots for better understanding.

In the network tab, Auth url is redirecting in a loop continues. Here is screenshot.

I tried to console the Auth response. Here is the screenshot of it. You can see the version as well.

And here is the configuration I did in my code.
vite.config.js file code ----->
`import vue from "@vitejs/plugin-vue";
import path from "path";
import { defineConfig, loadEnv } from "vite";
import basicSsl from "@vitejs/plugin-basic-ssl";
export default ({ command, mode }) => {
// Log command and mode for debugging if needed
console.log("Command", command, mode);
// Load environment variables based on build mode
const env = loadEnv(mode, process.cwd());
const isLocal = command === "serve";
return defineConfig({
plugins: [vue(), basicSsl()],
define: {
"process.env.NODE_ENV": JSON.stringify(isLocal ? "localServe" : env),
// Set NODE_ENV to "production" for production builds explicitly
"process.env": env,
},
resolve: {
alias: {
"@": path.resolve(__dirname, "./src"),
},
},
css: {
preprocessorOptions: {
scss: {
additionalData: @import "@/styles/global.scss";,
},
},
},
server: {
port: 8081,
https: true,
},
build: {
outDir: "dist", // Output directory for both JS and assets
assetsDir: "assets", // Separate directory for assets within dist
sourcemap: false, // Disable source maps in production
minify: true, // Enable minification in production
emptyOutDir: true, // Consider using multiple entry points if needed
rollupOptions: {
// input: path.resolve(__dirname, "./src/main.js"), // Single entry point (example)
// Add more entry points as needed
output: {
entryFileNames: "[name].js",
chunkFileNames: "[name].js",
assetFileNames: "[name].[ext]"
}
},
},
});
};
main.js file code ---->import { createApp } from "vue";
import { createPinia } from "pinia";
import '@okta/okta-auth-js/polyfill';
import { OktaAuth } from "@okta/okta-auth-js";
import OktaVue from "@okta/okta-vue";
import App from "./App.vue";
import router from "./router";
import axios from "axios";
import { createVuestic } from "vuestic-ui";
import "vuestic-ui/css";
import "material-design-icons-iconfont/dist/material-design-icons.min.css";
import CONFIG from "./config";
import VueDatePicker from "@vuepic/vue-datepicker";
import "@vuepic/vue-datepicker/dist/main.css";
export const oktaAuth = new OktaAuth({
clientId: CONFIG.OKTA.CLIENT_ID,
issuer: CONFIG.OKTA.ISSUER,
redirectUri: CONFIG.OKTA.REDIRECT_URI,
postLogoutRedirectUri: CONFIG.OKTA.POST_LOGOUT_REDIRECT_URI,
scopes: ["openid", "profile", "email"],
pkce: true,
});
console.log("oktaAuth ", oktaAuth);
const pinia = createPinia();
const app = createApp(App);
app.config.productionTip = false;
axios.defaults.withCredentials = true;
app.component("VueDatePicker", VueDatePicker);
app.use(
createVuestic({
config: {
colors: {
variables: {
primary: "#bf0000",
},
},
},
})
);
app.use(OktaVue, { oktaAuth });
app.use(router);
app.use(pinia);
app.mount("#app");
App.vue file code ----->
import { useWindowSizeStore } from "./stores/modules/windowSize";
import { useLoggedInUserStore } from "./stores/modules/loggedInUser";
import { useCouponStore } from "./stores/modules/coupons";
const $auth = useAuth();
const loggedInUser = useLoggedInUserStore();
const coupons = useCouponStore();
const { setWidth } = useWindowSizeStore();
onMounted(() => {
$auth.authStateManager.subscribe(async (authState) => {
if (authState.isAuthenticated) {
const accessToken = $auth.getAccessToken();
axios.defaults.headers.common["Authorization"] = Bearer ${accessToken};
await loggedInUser.getLoggedinUserFromAPI().then(() => {
const rstarRoleType = loggedInUser.getRStarRoleType;
if (rstarRoleType === "CLIENT" || rstarRoleType === "ADMIN") {
coupons.getCoupons();
}
});
}
});
setWidth(window.innerWidth);
window.addEventListener("resize", setWindowWidth, false);
});
onUnmounted(() => {
window.removeEventListener("resize", setWindowWidth, false);
});
const setWindowWidth = debounce(() => {
setWidth(window.innerWidth);
}, 0.01);
Reproduction Steps?
I hope the above information helps for understand. So, I am not able to provide steps to reproduce this issue. I am wondering my it is not able to generate the access token in a different env.
SDK Versions
{
"name": "client-ui",
"version": "2.0.0",
"private": true,
"main": "main.js",
"scripts": {
"start": "vite --mode localServe",
"build-local": "vite build --mode localServe",
"build-development": "vite build --mode development",
"build-staging": "vite build --mode staging",
"build-production": "vite build --mode production",
"watch": "vite build --watch --mode development",
"preview": "vite preview",
"test:unit": "vitest",
"lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs --fix --ignore-path .gitignore",
"format": "prettier --write src/"
},
"dependencies": {
"@okta/okta-auth-js": "^6.5.2",
"@okta/okta-vue": "^5.2.0",
"@vuepic/vue-datepicker": "^6.0.3",
"axios": "^1.6.2",
"chart.js": "^4.4.0",
"moment": "^2.29.4",
"papaparse": "^5.4.1",
"pinia": "^2.1.6",
"save": "^2.9.0",
"vue": "3.4.21",
"vue-chartjs": "^5.2.0",
"vue-router": "^4.3.0",
"vuestic-ui": "1.8.0"
},
"devDependencies": {
"@rushstack/eslint-patch": "^1.2.0",
"@vitejs/plugin-basic-ssl": "^1.0.1",
"@vitejs/plugin-vue": "^4.2.3",
"@vue/eslint-config-prettier": "^7.1.0",
"@vue/test-utils": "^2.3.2",
"eslint": "^8.39.0",
"eslint-plugin-vue": "^9.11.0",
"jsdom": "^22.0.0",
"material-design-icons-iconfont": "^6.7.0",
"prettier": "^2.8.8",
"sass": "^1.64.0",
"vite": "^5.1.6",
"vitest": "^1.3.1"
}
}
I am using node 20.9.0 version.
Additional Information
No response