mirror of
https://github.com/Bubka/2FAuth.git
synced 2024-11-22 16:23:18 +01:00
Move axios loader to bootstrap.js
This commit is contained in:
parent
8e4f8c4f8a
commit
8940efc225
1
resources/js/app.js
vendored
1
resources/js/app.js
vendored
@ -1,7 +1,6 @@
|
||||
import Vue from 'vue'
|
||||
import router from './routes'
|
||||
import i18n from './langs/i18n'
|
||||
import axios from './packages/axios'
|
||||
import FontAwesome from './packages/fontawesome'
|
||||
import App from './components/App'
|
||||
|
||||
|
30
resources/js/bootstrap.js
vendored
30
resources/js/bootstrap.js
vendored
@ -37,6 +37,36 @@ if (token) {
|
||||
console.error('CSRF token not found: https://laravel.com/docs/csrf#csrf-x-csrf-token');
|
||||
}
|
||||
|
||||
|
||||
window.axios.interceptors.request.use(function (request) {
|
||||
|
||||
const authToken = localStorage.getItem('jwt')
|
||||
|
||||
if(authToken) {
|
||||
request.headers.common['Authorization'] = 'Bearer ' + authToken
|
||||
}
|
||||
|
||||
request.headers.common['Content-Type'] = 'application/json'
|
||||
|
||||
return request
|
||||
|
||||
})
|
||||
|
||||
window.axios.interceptors.response.use(response => response, error => {
|
||||
|
||||
const { status } = error.response
|
||||
|
||||
if (status >= 500) {
|
||||
router.push({name: 'genericError', params: { err : error.response }})
|
||||
}
|
||||
|
||||
// if (status === 404) {
|
||||
// router.push({name: '404'})
|
||||
// }
|
||||
|
||||
return Promise.reject(error)
|
||||
})
|
||||
|
||||
/**
|
||||
* Echo exposes an expressive API for subscribing to channels and listening
|
||||
* for events that are broadcast by Laravel. Echo and event broadcasting
|
||||
|
56
resources/js/packages/axios.js
vendored
56
resources/js/packages/axios.js
vendored
@ -1,56 +0,0 @@
|
||||
import axios from 'axios'
|
||||
import router from '../routes'
|
||||
|
||||
|
||||
/**
|
||||
* We'll load the axios HTTP library which allows us to easily issue requests
|
||||
* to our Laravel back-end. This library automatically handles sending the
|
||||
* CSRF token as a header based on the value of the "XSRF" token cookie.
|
||||
*/
|
||||
|
||||
// window.axios = require('axios');
|
||||
|
||||
axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';
|
||||
|
||||
/**
|
||||
* Next we will register the CSRF Token as a common header with Axios so that
|
||||
* all outgoing HTTP requests automatically have it attached. This is just
|
||||
* a simple convenience so we don't have to attach every token manually.
|
||||
*/
|
||||
|
||||
let csrfToken = document.head.querySelector('meta[name="csrf-token"]');
|
||||
|
||||
if (csrfToken) {
|
||||
axios.defaults.headers.common['X-CSRF-TOKEN'] = csrfToken.content;
|
||||
} else {
|
||||
console.error('CSRF token not found: https://laravel.com/docs/csrf#csrf-x-csrf-token');
|
||||
}
|
||||
|
||||
axios.interceptors.request.use(request => {
|
||||
|
||||
const token = localStorage.getItem('jwt')
|
||||
|
||||
if(token) {
|
||||
request.headers.common['Authorization'] = 'Bearer ' + token
|
||||
}
|
||||
|
||||
request.headers.common['Content-Type'] = 'application/json'
|
||||
|
||||
return request
|
||||
})
|
||||
|
||||
// Response interceptor
|
||||
axios.interceptors.response.use(response => response, error => {
|
||||
|
||||
const { status } = error.response
|
||||
|
||||
if (status >= 500) {
|
||||
router.push({name: 'genericError', params: { err : error.response }})
|
||||
}
|
||||
|
||||
if (status === 404) {
|
||||
router.push({name: '404'})
|
||||
}
|
||||
|
||||
return Promise.reject(error)
|
||||
})
|
@ -81,7 +81,7 @@
|
||||
|
||||
|
||||
<script>
|
||||
// import axios from '../packages/axios'
|
||||
|
||||
import Modal from '../components/Modal'
|
||||
import TwofaccountShow from '../components/TwofaccountShow'
|
||||
import OneTimePassword from '../components/OneTimePassword'
|
||||
@ -127,6 +127,7 @@
|
||||
icon : data.icon
|
||||
})
|
||||
})
|
||||
|
||||
this.showAccounts = this.accounts.length > 0 ? true : false
|
||||
this.showNoAccount = !this.showAccounts
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user