Browse Source

chore(gui-v2): use state actions in api plugin

Signed-off-by: Braks <78412429+bcakmakoglu@users.noreply.github.com>
pull/2716/head
Braks 2 years ago committed by Pranav C
parent
commit
5089a43557
  1. 10
      packages/nc-gui-v2/plugins/api.ts

10
packages/nc-gui-v2/plugins/api.ts

@ -1,5 +1,5 @@
import { Api } from 'nocodb-sdk'
import { defineNuxtPlugin } from '#app'
import { defineNuxtPlugin, navigateTo } from '#app'
import type { GlobalState } from '~/lib/types'
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
if (error.config.url === '/auth/refresh-token') {
app.$state.token.value = null
app.$state.signOut()
return new Promise((resolve, reject) => {
reject(error)
@ -66,7 +66,7 @@ function addAxiosInterceptors(api: Api<any>, app: { $state: GlobalState }) {
// New request with new token
const config = error.config
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) => {
api.instance
@ -80,10 +80,10 @@ function addAxiosInterceptors(api: Api<any>, app: { $state: GlobalState }) {
})
})
.catch(async (error) => {
app.$state.token.value = null
app.$state.signOut()
// todo: handle new user
router.replace('/signin')
navigateTo('/signIn')
return Promise.reject(error)
})

Loading…
Cancel
Save