mirror of
https://github.com/bitinflow/nuxt-oauth.git
synced 2026-03-13 13:45:59 +00:00
29 lines
607 B
TypeScript
29 lines
607 B
TypeScript
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://accounts.bitinflow.com/api/v3/',
|
|
headers: {
|
|
common: {
|
|
'Authorization': bearerToken(),
|
|
},
|
|
},
|
|
});
|
|
|
|
watch(accessToken, () => {
|
|
console.log('access token rotated')
|
|
api.defaults.headers.common['Authorization'] = bearerToken();
|
|
});
|
|
|
|
return {
|
|
provide: {
|
|
api: api,
|
|
},
|
|
};
|
|
});
|