How to get access token of auth0 in Vue app just mounted

Viewed 481

I can get access token in methods. But, I can't get access token in mounted() and created().

https://auth0.com/docs/quickstart/spa/vuejs/01-login

i added for quickstart sample in this.accessToken = await this.auth0Client.getTokenSilently();

app.js

...

// Import the Auth0 configuration
import { domain, clientId, audience } from "./auth/auth_config.json";

// Import the plugin here
import { Auth0Plugin } from "./auth";

// Install the authentication plugin here
Vue.use(Auth0Plugin, {
  domain,
  clientId,
  audience,
  onRedirectCallback: appState => {
    router.push(
      appState && appState.targetUrl
        ? appState.targetUrl
        : window.location.pathname
    );
  }
});

...

test.vue

<template>
  <div>
    Auth0 Email: {{ $auth.user.email }}
    Auth0 AccessToken: {{ tokenOutput() }}
  </div>
</template>

<script>
  export default {
    async created() {
      console.log(await this.$auth.accessToken); // null
    },
    async mounted() {
      console.log(await this.$auth.accessToken); // null
    },
    methods: {
      tokenOutput: function(){
        return this.$auth.accessToken;
      }
    }
  }
</script>

$auth.user.email and tokenOutput() is output. but, this.$auth.accessToken is null. can i get access token of auth0 in Vue app just mounted.

Thanks.

0 Answers
Related