From 1b54fada3b81cdb91d84ba52674a78628cb96037 Mon Sep 17 00:00:00 2001 From: Albert Chen Date: Sat, 6 Jan 2018 16:26:30 +0800 Subject: [PATCH] implement refresh token in axios inceptor --- resources/assets/js/plugins/axios.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/resources/assets/js/plugins/axios.js b/resources/assets/js/plugins/axios.js index 1eb0ee1..603230f 100644 --- a/resources/assets/js/plugins/axios.js +++ b/resources/assets/js/plugins/axios.js @@ -22,7 +22,19 @@ axios.interceptors.request.use(request => { }) // Response interceptor -axios.interceptors.response.use(response => response, error => { +axios.interceptors.response.use(response => { + const { authorization } = response.headers + + if (authorization) { + store.dispatch('auth/saveToken', { + token: authorization.split(' ').pop(), + remember: false + }) + } + + return response + + }, error => { const { status } = error.response if (status >= 500) {