mirror of
https://github.com/bitinflow/nuxt-oauth.git
synced 2026-03-13 13:45:59 +00:00
Fix ref for watch
This commit is contained in:
28
playground/plugins/axios.ts
Normal file
28
playground/plugins/axios.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import axios from "axios";
|
||||
import {useAuth} from "#imports";
|
||||
import {defineNuxtPlugin} from '#app';
|
||||
import {watch} from 'vue';
|
||||
|
||||
export default defineNuxtPlugin(async () => {
|
||||
const {bearerToken, accessToken} = await useAuth();
|
||||
|
||||
const api = axios.create({
|
||||
baseURL: 'https://id.stream.tv/api/',
|
||||
headers: {
|
||||
common: {
|
||||
'Authorization': bearerToken(),
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
watch(accessToken, () => {
|
||||
console.log('access token rotated')
|
||||
api.defaults.headers.common['Authorization'] = bearerToken();
|
||||
});
|
||||
|
||||
return {
|
||||
provide: {
|
||||
api: api,
|
||||
},
|
||||
};
|
||||
});
|
||||
Reference in New Issue
Block a user