- fix: refresh token, codice di errore ...

This commit is contained in:
Surya Paolo
2025-03-15 14:52:25 +01:00
parent dfce2bc5eb
commit 201b739c8c
59 changed files with 726 additions and 87 deletions

View File

@@ -6,7 +6,7 @@ import type * as Types from '@src/store/Api/ApiTypes'
// Funzione che smista la richiesta in base al metodo
async function sendRequest(url, method, mydata, myformdata, responsedata, options) {
async function sendRequest(url, method, mydata, myformdata = null, responsedata = null, options = null) {
const actions = {
get: () => Api.get(url, mydata, responsedata),
post: () => Api.post(url, mydata, responsedata, options),

View File

@@ -114,9 +114,9 @@ export const Api = {
} catch (error) {
console.error('Errore durante il refresh token:', error);
// Logout dell'utente in caso di errore critico
userStore.setAuth('', '');
localStorage.removeItem(toolsext.localStorage.token);
localStorage.removeItem(toolsext.localStorage.refreshToken);
// userStore.setAuth('', '');
// localStorage.removeItem(toolsext.localStorage.token);
// localStorage.removeItem(toolsext.localStorage.refreshToken);
throw error;
}
},
@@ -147,15 +147,15 @@ export const Api = {
if (err2?.code === serv_constants.RIS_CODE__HTTP_FORBIDDEN_INVALID_TOKEN) {
userStore.setServerCode(toolsext.ERR_AUTHENTICATION);
// userStore.setAuth('', '');
throw { status: toolsext.ERR_RETRY_LOGIN };
userStore.setAuth('', '');
throw { status: err2.code };
}
// Gestione di altri errori critici
throw err2;
}
} else if (status === serv_constants.RIS_CODE__HTTP_FORBIDDEN_INVALID_TOKEN) {
// userStore.setAuth('', '');
userStore.setAuth('', '');
const $router = useRouter()
throw { status: toolsext.ERR_RETRY_LOGIN };
}

View File

@@ -220,7 +220,7 @@ export const costanti = {
to: '/circuits',
table: 'circuits',
icon: 'fas fa-coins',
image: 'images/1ris_rosso_100.png',
image: '/images/1ris_rosso_100.png',
color: 'orange-6',
hint: '',
disable: true,
@@ -488,7 +488,7 @@ export const costanti = {
Nessuno: 0,
Entrata: 1,
Uscita: -1,
},
},
FieldTypeArr: [
{ label: 'Boolean', value: 1 },

View File

@@ -2998,7 +2998,7 @@ export const tools = {
},
getimglogo() {
return `images/${import.meta.env.VITE_LOGO_REG}`
return `/images/${import.meta.env.VITE_LOGO_REG}`
},
consolelogpao(strlog: string, strlog2: any = '', strlog3: any = '') {
@@ -9238,18 +9238,18 @@ export const tools = {
let addtourl = ''
if (!gallerylist) {
return 'images/noimg.png';
return '/images/noimg.png';
}
if (gallerylist && gallerylist.vers_img) {
addtourl = '?v=' + gallerylist.vers_img
}
if (gallerylist && !gallerylist.imagefile) {
return 'images/noimg.png';
return '/images/noimg.png';
}
if (gallerylist) {
if (this.getextfile(gallerylist.imagefile) === 'pdf')
return 'images/images/pdf.jpg'
return '/images/images/pdf.jpg'
else {
if (this.contieneSlash(gallerylist.imagefile)) {
return gallerylist.imagefile + addtourl
@@ -9259,7 +9259,7 @@ export const tools = {
}
} else {
return 'images/noimg.png';
return '/images/noimg.png';
}
},

View File

@@ -424,7 +424,7 @@ export const useUserStore = defineStore('UserStore', {
getImgUserByUsername(username: string): string {
const img = this.getImgByUsername(username)
return img ? img : 'images/noimg-user.svg'
return img ? img : '/images/noimg-user.svg'
},
getImgUserByRow(row: any, col: IColGridTable): string {
@@ -453,7 +453,7 @@ export const useUserStore = defineStore('UserStore', {
}
}
return img ? img : 'images/noimg-user.svg'
return img ? img : '/images/noimg-user.svg'
},
getImgByProfile(userparam: any, reale: any = false, col: any = null): string {
@@ -461,7 +461,7 @@ export const useUserStore = defineStore('UserStore', {
let myrec = this.getRecByCol(userparam, col)
let img = ''
if (!reale)
img = 'images/noimg-user.svg'
img = '/images/noimg-user.svg'
let tipoconto = shared_consts.AccountType.USER
if (col && tools.existProp(col, 'tipoconto') && col.tipoconto) {
@@ -483,7 +483,7 @@ export const useUserStore = defineStore('UserStore', {
//
}
if (!reale)
return 'images/noimg-user.svg'
return '/images/noimg-user.svg'
else
return ''
},
@@ -493,7 +493,7 @@ export const useUserStore = defineStore('UserStore', {
let img = ''
if (!reale)
img = 'images/noimg-user.svg'
img = '/images/noimg-user.svg'
if (tipoconto === shared_consts.AccountType.COLLECTIVE_ACCOUNT) {
img = this.getImgByGroup(from ? mov.groupfrom : mov.groupto)
@@ -512,7 +512,7 @@ export const useUserStore = defineStore('UserStore', {
//
}
if (!reale)
return 'images/noimg-user.svg'
return '/images/noimg-user.svg'
else
return ''
},
@@ -658,7 +658,7 @@ export const useUserStore = defineStore('UserStore', {
return tools.getDirUpload() + 'circuits/' + circ.path + '/' + circ.photos[0].imagefile
} catch (e) {
}
return 'images/noimg.png'
return '/images/noimg.png'
},
getImgByCircuitpath(circuitpath: string): string {
@@ -677,7 +677,7 @@ export const useUserStore = defineStore('UserStore', {
}
} catch (e) {
}
return 'images/noimg.png'
return '/images/noimg.png'
},
getImgByGroupname(groupname: string): string {

View File

@@ -1023,9 +1023,11 @@ export const useGlobalStore = defineStore('GlobalStore', {
let stop = false
if (!await this.loadSite()) {
const { ris, status } = await this.loadSite()
if (status === toolsext.ERR_RETRY_LOGIN) {
stop = true
code = toolsext.ERR_RETRY_LOGIN
code = status
} else {
isok = true
}
@@ -1740,6 +1742,8 @@ export const useGlobalStore = defineStore('GlobalStore', {
const Products = useProducts()
const catalogStore = useCatalogStore()
let status = 0
// console.log('calendarStore: loadAfterLogin')
// Load local data
const showall = userStore.isAdmin || userStore.isManager ? '1' : '0'
@@ -1750,6 +1754,7 @@ export const useGlobalStore = defineStore('GlobalStore', {
try {
const res = await Api.SendReq(`/loadsite/${myuserid}/${tools.getEnv('VITE_APP_ID')}/${import.meta.env.VITE_APP_VERSION}`, 'GET', null)
status = res.status
if (res.status === 200) {
console.log('____________________________ res', res)
@@ -1884,15 +1889,18 @@ export const useGlobalStore = defineStore('GlobalStore', {
}
}
return true
return { ris: true, status }
} else {
}
} catch (error) {
status = error.status
if (error.status === toolsext.ERR_RETRY_LOGIN) {
} else {
if (error.status === serv_constants.RIS_CODE__HTTP_FORBIDDEN_TOKEN_EXPIRED) {
if (error.status === serv_constants.RIS_CODE__HTTP_FORBIDDEN_TOKEN_EXPIRED ||
error.status === serv_constants.RIS_CODE__HTTP_FORBIDDEN_INVALID_TOKEN
) {
} else {
this.serverError = true
@@ -1904,10 +1912,10 @@ export const useGlobalStore = defineStore('GlobalStore', {
this.serverMsgError = error
//return new Types.AxiosError(serv_constants.RIS_CODE_ERR, null, toolsext.ERR_GENERICO, error)
return false
return { ris: false, status }
}
return false
return { ris: false, status }
},
getProvinceByProv(provstr: string) {