mirror of
https://github.com/kevin-DL/comedy-video-lib.git
synced 2026-01-14 12:04:46 +00:00
Logged in/ Logged out
- Created midlewares for authenticated and guest] - Add the token to the api calls - Added redirect after the login
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
export default function ({ $axios }, inject) {
|
||||
export default function ({ $axios, store }, inject) {
|
||||
// Create a custom axios instance
|
||||
const api = $axios.create({
|
||||
headers: {
|
||||
@@ -11,6 +11,28 @@ export default function ({ $axios }, inject) {
|
||||
// Set baseURL to something different
|
||||
api.setBaseURL(process.env.baseApiUrl)
|
||||
|
||||
api.onRequest(config => {
|
||||
config.headers = {
|
||||
...config.headers,
|
||||
Authorization: store.state.auth.token
|
||||
}
|
||||
})
|
||||
|
||||
// Inject to context as $api
|
||||
inject('api', api)
|
||||
}
|
||||
|
||||
|
||||
// export default function ({ $axios, redirect }) {
|
||||
// $axios.s
|
||||
// $axios.onRequest(config => {
|
||||
// console.log('Making request to ' + config.url)
|
||||
// })
|
||||
//
|
||||
// $axios.onError(error => {
|
||||
// const code = parseInt(error.response && error.response.status)
|
||||
// if (code === 400) {
|
||||
// redirect('/400')
|
||||
// }
|
||||
// })
|
||||
// }
|
||||
|
||||
Reference in New Issue
Block a user