I make requests to the API in separate files, for example:
// ~/api/request.ts
import axios from 'axios'
export const testMethod = async (
email: string
) => {
try {
return await axios.post('/test-route/', { email })
} catch (error) {
if (error.code === '401') {
//
}
}
}
I want:
- To add error handling, if the token has expired, then redirect to the authorization page and clear store.
- Create axios instance with Authorization header, with token from Vuex
How do I access the Nuxt context from this file?