|
|
@ -1,5 +1,5 @@ |
|
|
|
import { Api } from 'nocodb-sdk' |
|
|
|
import { Api } from 'nocodb-sdk' |
|
|
|
import { defineNuxtPlugin } from '#app' |
|
|
|
import { defineNuxtPlugin, navigateTo } from '#app' |
|
|
|
import type { GlobalState } from '~/lib/types' |
|
|
|
import type { GlobalState } from '~/lib/types' |
|
|
|
|
|
|
|
|
|
|
|
export default defineNuxtPlugin((nuxtApp) => { |
|
|
|
export default defineNuxtPlugin((nuxtApp) => { |
|
|
@ -50,7 +50,7 @@ function addAxiosInterceptors(api: Api<any>, app: { $state: GlobalState }) { |
|
|
|
|
|
|
|
|
|
|
|
// Logout user if token refresh didn't work or user is disabled
|
|
|
|
// Logout user if token refresh didn't work or user is disabled
|
|
|
|
if (error.config.url === '/auth/refresh-token') { |
|
|
|
if (error.config.url === '/auth/refresh-token') { |
|
|
|
app.$state.token.value = null |
|
|
|
app.$state.signOut() |
|
|
|
|
|
|
|
|
|
|
|
return new Promise((resolve, reject) => { |
|
|
|
return new Promise((resolve, reject) => { |
|
|
|
reject(error) |
|
|
|
reject(error) |
|
|
@ -66,7 +66,7 @@ function addAxiosInterceptors(api: Api<any>, app: { $state: GlobalState }) { |
|
|
|
// New request with new token
|
|
|
|
// New request with new token
|
|
|
|
const config = error.config |
|
|
|
const config = error.config |
|
|
|
config.headers['xc-auth'] = token.data.token |
|
|
|
config.headers['xc-auth'] = token.data.token |
|
|
|
if (app.$state.token.value) app.$state.token.value = token.data.token |
|
|
|
if (app.$state.token.value) app.$state.signIn(token.data.token) |
|
|
|
|
|
|
|
|
|
|
|
return new Promise((resolve, reject) => { |
|
|
|
return new Promise((resolve, reject) => { |
|
|
|
api.instance |
|
|
|
api.instance |
|
|
@ -80,10 +80,10 @@ function addAxiosInterceptors(api: Api<any>, app: { $state: GlobalState }) { |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
.catch(async (error) => { |
|
|
|
.catch(async (error) => { |
|
|
|
app.$state.token.value = null |
|
|
|
app.$state.signOut() |
|
|
|
// todo: handle new user
|
|
|
|
// todo: handle new user
|
|
|
|
|
|
|
|
|
|
|
|
router.replace('/signin') |
|
|
|
navigateTo('/signIn') |
|
|
|
|
|
|
|
|
|
|
|
return Promise.reject(error) |
|
|
|
return Promise.reject(error) |
|
|
|
}) |
|
|
|
}) |
|
|
|