I'm submitting a:
Current behavior
Our Vue single page application fails on startup and displays a blank page stemming from an error that originates from within the Okta Plugin within @okta/okta-vue/Auth.js that indicates the internal instance of await oktaAuth is undefined and fails to establish a user identity from an accessToken/idToken.
Uncaught (in promise) TypeError: Cannot read property 'oktaAuth' of undefined
at _callee$ (webpack-internal:///./src/router/index.js:94)
at tryCatch (webpack-internal:///./node_modules/regenerator-runtime/runtime.js:62)
at Generator.invoke [as _invoke] (webpack-internal:///./node_modules/regenerator-runtime/runtime.js:296)
at Generator.prototype.<computed> [as next] (webpack-internal:///./node_modules/regenerator-runtime/runtime.js:114)
at step (webpack-internal:///./node_modules/@vue/babel-preset-app/node_modules/@babel/runtime/helpers/builtin/es6/asyncToGenerator.js:12)
at _next (webpack-internal:///./node_modules/@vue/babel-preset-app/node_modules/@babel/runtime/helpers/builtin/es6/asyncToGenerator.js:27)
Expected behavior
We expect the normal behavior where the redirect to Okta to result in either in a successful login or refresh of the existing access and id token. In either case we expect the library to always internally resolve to a defined (non-null and non-undefined) instance in all of the references to: "this.oktaAuth"
Minimal reproduction of the problem with instructions
- Create new Vue application
- Add this route initializer
Note: In the code snippet below, you see that our initialization of the Auth plugin uses defaults that result in autoRenew: true and the use of local storage. And because our application displays confidential data, we take a vigilant approach to checking the user on each route change that uses the router::beforeEach() and router::beforeResolve() event hooks. The intent is to ensure we authenticate users and renew session tokens via router::beforeEach() event and subsequently invalidate/synchronize the user in the router::beforeResolve() event handler.
import Auth from '@okta/okta-vue'
import store from '@state/store'
Vue.use(Auth, {
issuer: process.env.VUE_APP_OKTA_ISSUER_URL,
clientId: process.env.VUE_APP_OKTA_CLIENT_ID,
redirectUri: `${window.location.origin}/implicit/callback`,
scopes: ['openid', 'profile', 'email'],
pkce: true,
})
Vue.use(VueRouter)
Vue.use(VueMeta, {
// The component option name that vue-meta looks for meta info on.
keyName: 'page',
})
const router = new VueRouter({
routes: allRoutes,
scrollBehavior(to, from, savedPosition) {
if (savedPosition) {
return savedPosition
} else {
return { x: 0, y: 0 }
}
},
})
- Add these pre and post route guards to ensure only authenticated users are granted access
router.beforeEach(Vue.prototype.$auth.authRedirectGuard())
router.beforeResolve(async (routeTo, routeFrom, next) => {
// Fetch actively logged in use from IDP and conditionally update store
const authenticatedIDPUser = await Vue.prototype.$auth.getUser()
if (!authenticatedIDPUser) {
debugger
alert('[router.beforeResolve] "$auth.getUser()" returned null/undefined')
}
const isAuthorizedUserLoggedIn = store.getters['auth/isLoggedIn']
const synchronizeUserStoreRequired = authenticatedIDPUser && !isAuthorizedUserLoggedIn
if (synchronizeUserStoreRequired) {
await store.dispatch('auth/onLoggedIn', Vue.prototype.$auth)
}
// If we reach this point, continue resolving the route.
next()
})
- start application via
npm run serve
Extra information about the use case/user story you are trying to implement
We need to ensure each user is authenticated and has a valid access token before access is granted to the application and data is displayed via APIs.
Environment
- Package version: 1.1.1
- Vue version: 2.6.10
- Browser: Chrome
- OS: MacOS Mojave, i.e. OSX 10.14.5
- Node version (
node -v): 12.0.0
- Other:
I'm submitting a:
Current behavior
Our Vue single page application fails on startup and displays a blank page stemming from an error that originates from within the Okta Plugin within @okta/okta-vue/Auth.js that indicates the internal instance of await oktaAuth is undefined and fails to establish a user identity from an accessToken/idToken.
Expected behavior
We expect the normal behavior where the redirect to Okta to result in either in a successful login or refresh of the existing access and id token. In either case we expect the library to always internally resolve to a defined (non-null and non-undefined) instance in all of the references to: "this.oktaAuth"
Minimal reproduction of the problem with instructions
Note: In the code snippet below, you see that our initialization of the Auth plugin uses defaults that result in autoRenew: true and the use of local storage. And because our application displays confidential data, we take a vigilant approach to checking the user on each route change that uses the router::beforeEach() and router::beforeResolve() event hooks. The intent is to ensure we authenticate users and renew session tokens via router::beforeEach() event and subsequently invalidate/synchronize the user in the router::beforeResolve() event handler.
npm run serveExtra information about the use case/user story you are trying to implement
We need to ensure each user is authenticated and has a valid access token before access is granted to the application and data is displayed via APIs.
Environment
node -v): 12.0.0