mirror of
https://bitbucket.org/studiotem/jandl-taskmanager-app.git
synced 2026-10-22 14:59:34 +00:00
.
This commit is contained in:
1 parent
1550406534
commit
b52b5114e6
5 files changed
+21
-16
No files matched your search
@@ -35,8 +35,9 @@ export default {
|
||||
actions: {
|
||||
login({commit}: {commit: any}, credentials: any) {
|
||||
return new Promise((resolve, reject) => {
|
||||
axios.post_data('v1/auth/login', credentials)
|
||||
axios.post('v1/tokens/create', credentials)
|
||||
.then((response: any) => {
|
||||
console.log(response)
|
||||
const token = response.token
|
||||
const user = response.user
|
||||
|
||||
|
||||
@@ -1,16 +1,12 @@
|
||||
import store from '@/store'
|
||||
/* eslint-disable */
|
||||
import axios from 'axios'
|
||||
import createAuthRefreshInterceptor from 'axios-auth-refresh'
|
||||
import store from '@/store'
|
||||
|
||||
axios.interceptors.request.use(request => {
|
||||
request.headers['Authorization'] = `Bearer ${store.getters['user/token']}`
|
||||
return request
|
||||
})
|
||||
|
||||
const refreshAuthLogic = failedRequest => store.dispatch('user/refreshToken').then(token => {
|
||||
failedRequest.response.config.headers.Authorization = `Bearer ${token}`
|
||||
return Promise.resolve()
|
||||
})
|
||||
|
||||
createAuthRefreshInterceptor(axios, refreshAuthLogic)
|
||||
async function _unauthorised(error: any) {
|
||||
return store.dispatch('auth/logout')
|
||||
}
|
||||
|
||||
axios.interceptors.response.use(
|
||||
(response) => response,
|
||||
(error) => _unauthorised(error),
|
||||
)
|
||||
Reference in new issue
Block a user