Okta-vue 3.1 this.$auth.getAccessToken(); does it return a promise or is is synchronous?

simple question:

In Okta-vue 3.1

if i call it like this, it works.


but if i put

this.$auth.getAccessToken().then((token) => { //<---------blow up here saying it’s not a function.
this.$store.commit(‘SET_ACCESS_TOKEN’, token)
localStorage.setItem(‘token’, JSON.stringify(token))
apiClient.defaults.headers.common.Authorization = Bearer ${token}

I get an error that’s it’s not a function at runtime only.

Does it return a promise or is is synchronous?

Or am I just having weird scope issues…


Doesn’t look like its supposed to return a promise, just the access token string and our documentation does not indicate this is an async function as it does for others: getAccessToken | Okta Auth Javascript SDK

I think it should return the promise as we are calling Okta(outside of vue application).

I agree, a version that returned a promise would make this code a lot cleaner, but it currently does not.

Hello, as you said, the doc define the function as string | undefined but the thing it is a Promise internally because the generation of a token take some time, I personally have problems with this, if a request is made to my backend and token expired, i have a hook to renew the token in the frontend, but some times it takes time and the result is the awkward error 401. I have see some code of okta and realized that in deed the function is a Promise but in some places it is just used a direct string. Why?

Doing a quick search you see in the public code that in the tests the function is handled as Promise, but described as string | undefined