我可以在方法中获取访问令牌。 但是,我无法在mount()和created()中获得访问令牌。
https://auth0.com/docs/quickstart/spa/vuejs/01-login
我在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
和tokenOutput()
输出。
但是this.$auth.accessToken
为空。
我可以在刚刚安装的Vue应用中获取auth0的访问令牌吗?
谢谢。