# Issue with $auth being null

**URL:** <https://community.auth0.com/t/issue-with-auth-being-null/44642>\
**Category:** Get Help\
**Tags:** auth0-spa-js, vuejs\
**Created:** [June 14, 2020, 4:41am UTC](https://community.auth0.com/t/issue-with-auth-being-null/44642 "2020-06-14T04:41:44Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Simisav](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/simisav/32/21930_2.png) [@Simisav](https://community.auth0.com/u/Simisav)\
**Post date:** [June 14, 2020, 4:41am UTC](https://community.auth0.com/t/issue-with-auth-being-null/44642/1 "2020-06-14T04:41:44Z")

</div>

I am building a web application with Vue.js. I am trying to add Auth0 by going through the Auth0 Vue SDK Quickstart. I am able to get the user to log in and display their user information on a profile page. $auth is valid in all of my Vue components.

The issue is I am trying to create an API client with Axios that uses an interceptor to add an Authorization header. When I try to use` $auth.getTokenSilently()` `$auth` is always `null`. I’m doing something very similar to [vuejs · Discussions · GitHub](https://forum.vuejs.org/t/using-auth0-spa-with-axios-wrapper/79187/3). I also tried to use this [The prototype this.$auth in Vue main.js always null - #3 by damir](http://community.auth0.com/t/the-prototype-this-auth-in-vue-main-js-always-null/31993/3) to fix the issue but `getInstance()` is null.

Here is my main.js

```auto
Vue.use(Auth0Plugin, {
  domain,
  clientId,
  onRedirectCallback: appState => {
    router.push(
      appState && appState.targetUrl
        ? appState.targetUrl
        : window.location.pathname

const myApp = new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')

export default myApp;

```

Repository.js

```auto
import axios from 'axios';
import myApp from "@/App";

const baseDomain = 'http://localhost:8000';
const baseURL = `${baseDomain}/api`;

export const httpClient = axios.create({
  baseURL: baseURL,
  headers: {
    "Context-Type": "application/json"
  }
});

httpClient.interceptors.request.use(async (config) => {
  const token = await myApp.$auth.getTokenSilently(); 
  config.headers['Authorization'] = `Bearer ${token}`;
  return config
}, (error) => {
  return Promise.reject(error);
})

```

Then in my store.js (Vuex) I am using a factory pattern to use the httpClient. It seems the interceptor is running before Auth0 is fully loaded. If you have any ideas please let me know!

Seems like I should make sure auth0 is ready before anything else.

---

<div class="post-metadata">

**Author:** ![Simisav](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/simisav/32/21930_2.png) [@Simisav](https://community.auth0.com/u/Simisav)\
**Post date:** [June 20, 2020, 12:27am UTC](https://community.auth0.com/t/issue-with-auth-being-null/44642/2 "2020-06-20T00:27:38Z")

</div>

After trying a few different solutions this one worked! Make sure to await on the action. Let me know if you have any questions.

> [@Auth0 client is null in Vue SPA component on page refresh](http://community.auth0.com/t/auth0-client-is-null-in-vue-spa-component-on-page-refresh/38147/6):
>
> I used the solution provided above and managed to put it into a single Vuex action. The whole Vuex module to those interested: import { getInstance } from "@/auth"; const state = { token: null }; const getters = { token(state) { return state.token; } }; const mutations = { setToken(state, token) { state.token = token; } }; const actions = { retrieveTokenFromAuthz(context) { return new Promise((resolve, reject) =\> { const instance = getInstance(); instance…

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [June 22, 2020, 11:16am UTC](https://community.auth0.com/t/issue-with-auth-being-null/44642/3 "2020-06-22T11:16:49Z")

</div>

Thanks for sharing it with the rest of community!

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [July 7, 2020, 11:16am UTC](https://community.auth0.com/t/issue-with-auth-being-null/44642/4 "2020-07-07T11:16:49Z")

</div>

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.
