mirror of
https://gitlab.com/bramw/baserow.git
synced 2025-04-12 16:28:06 +00:00
24 lines
789 B
JavaScript
24 lines
789 B
JavaScript
import { client } from '@/services/client'
|
|
|
|
export default function({ store }) {
|
|
// Create a request interceptor to add the authorization token to every
|
|
// request if the user is authenticated.
|
|
client.interceptors.request.use(config => {
|
|
if (store.getters['auth/isAuthenticated']) {
|
|
const token = store.getters['auth/token']
|
|
config.headers.Authorization = `JWT ${token}`
|
|
}
|
|
return config
|
|
})
|
|
|
|
// If the user is authenticated, but is not refreshing in the browser means
|
|
// that the refresh was done on the server side, so we need to manually start
|
|
// the refreshing timeout here.
|
|
if (
|
|
store.getters['auth/isAuthenticated'] &&
|
|
!store.getters['auth/isRefreshing'] &&
|
|
process.browser
|
|
) {
|
|
store.dispatch('auth/startRefreshTimeout')
|
|
}
|
|
}
|