- corretto problema ROGNOSO : Risolvere la questione "Sessioni multiple", se apro 2 browser l'ultimo va a cancellare il precedente, e mi da errore di email non valida !

Il problema era sulla fetch nel service worker, gestita in quel modo personalizzato, andava in conflitto, non tenendo le chiamate bloccanti, ma uscivano prima che arrivasse la risposta del server.
- Per chi è da tanto che non si collega a RISO, compare "Email non verificata"... (si risolve chiudendo su ESCI e riloggandosi)... però andrebbe sistemata.
(stesso problema di prima).
This commit is contained in:
Surya Paolo
2025-10-26 02:47:59 +02:00
parent eb0fb72c70
commit df98ec9471
64 changed files with 1286 additions and 704 deletions

View File

@@ -1,61 +1,66 @@
import type { AxiosRequestConfig, AxiosInstance, AxiosResponse } from 'axios';
import axios from 'axios'
import axios from 'axios';
// import LoginModule from '../Modules/Auth/LoginStore'
import { toolsext } from '@src/store/Modules/toolsext'
import { serv_constants } from '@src/store/Modules/serv_constants'
import { useGlobalStore } from '@store/globalStore'
import { useUserStore } from '@store/UserStore'
import { tools } from '@src/store/Modules/tools'
import * as Types from './ApiTypes'
import { toolsext } from '@src/store/Modules/toolsext';
import { serv_constants } from '@src/store/Modules/serv_constants';
import { useGlobalStore } from '@store/globalStore';
import { useUserStore } from '@store/UserStore';
import { tools } from '@src/store/Modules/tools';
import * as Types from './ApiTypes';
import type { Observable } from 'rxjs';
import { from } from 'rxjs';
import { mergeMap, toArray } from 'rxjs/operators';
export let API_URL = ''
export let API_URL = '';
export const axiosInstance: AxiosInstance = axios.create({
baseURL: API_URL,
headers: {
Accept: 'application/json',
},
})
axiosInstance.interceptors.response.use(
});
/*axiosInstance.interceptors.response.use(
(response) => {
if (import.meta.env.VITE_DEBUG === '1') console.log(response)
return response
if (import.meta.env.VITE_DEBUG === '1') console.log(response);
return response;
},
(error) => {
const globalStore = useGlobalStore()
const globalStore = useGlobalStore();
// console.log('error', error)
if (error.response) {
if (import.meta.env.VITE_DEBUG === '1') console.log('Status = ', error.response.status)
console.log('Request Error: ', error.response)
if (import.meta.env.VITE_DEBUG === '1')
console.log('Status = ', error.response.status);
console.log('Request Error: ', error.response);
if (error.response.status !== 0) {
globalStore.setStateConnection('online')
globalStore.setStateConnection('online');
} else {
globalStore.setStateConnection('offline')
globalStore.setStateConnection('offline');
}
} else {
globalStore.setStateConnection('offline')
globalStore.setStateConnection('offline');
}
return Promise.reject(error)
},
)
return Promise.reject(error);
}
);
*/
export const addAuthHeaders = () => {
// axiosInstance.defaults.headers.Authorization = `Bearer ${LoginModule.userInfos.userToken}`
}
};
//export const removeAuthHeaders = () => {
// delete axiosInstance.defaults.headers.Authorization
//}
async function generateStream(path: string, payload: any, config?: RequestInit, options?: any): Promise<AsyncIterable<any>> {
const userStore = useUserStore()
async function generateStream(
path: string,
payload: any,
config?: RequestInit,
options?: any
): Promise<AsyncIterable<any>> {
const userStore = useUserStore();
const mieiparam: any = {
method: 'POST',
@@ -66,16 +71,13 @@ async function generateStream(path: string, payload: any, config?: RequestInit,
},
body: JSON.stringify(payload),
signal: options?.signal,
...config
}
...config,
};
console.log('marams: ', mieiparam)
console.log('marams: ', mieiparam);
const response = await fetch(
path,
mieiparam,
);
console.log('USCITA DA FETCH... !!!!!')
const response = await fetch(path, mieiparam);
console.log('USCITA DA FETCH... !!!!!');
if (response.status !== 200) throw new Error(response.status.toString());
return getIterableStream(response);
}
@@ -112,17 +114,25 @@ function getIterableStream(stream: NodeJS.ReadableStream): AsyncIterable<any> {
}
// Funzione helper per inviare la richiesta HTTP
async function Request(type: string, path: string, payload: any, responsedata = {}, options: any = {}) {
async function Request(
type: string,
path: string,
payload: any,
responsedata = {},
options: any = {}
) {
const userStore = useUserStore();
const globalStore = useGlobalStore();
const baseURL = globalStore.getServerHost();
try {
if (tools.isDebug()) console.log('Axios Request', path, type, tools.notshowPwd(payload));
if (tools.isDebug())
console.log('Axios Request', path, type, tools.notshowPwd(payload));
const isFormData = type === 'postFormData';
const config = {
let config: AxiosRequestConfig = {
baseURL,
timeout: 60000,
headers: {
'Content-Type': isFormData ? 'multipart/form-data' : 'application/json',
'x-auth': userStore.x_auth_token,
@@ -138,7 +148,7 @@ async function Request(type: string, path: string, payload: any, responsedata =
if (options?.stream) config.responseType = 'stream';
let response;
let response: any;
const method = type.toLowerCase();
// Gestione dinamica del metodo HTTP
@@ -149,7 +159,7 @@ async function Request(type: string, path: string, payload: any, responsedata =
return new Promise((resolve, reject) => {
from(stream)
.pipe(
mergeMap(event => from([event])),
mergeMap((event) => from([event])),
toArray()
)
.subscribe(
@@ -174,7 +184,21 @@ async function Request(type: string, path: string, payload: any, responsedata =
response = await axiosInstance[method](path, payload, config);
}
} else if (['get', 'delete'].includes(method)) {
response = await axiosInstance[method](path, {
config.params = payload;
config.headers = {
...config.headers,
'Content-Type': 'application/json',
};
//console.log('FACCIO LA CHIAMATA axiosInstance' + method)
//console.log('. path', path);
//console.log('. config', config);
response = await axiosInstance[method](path, config ? config : {}); // ✅ CORRETTO
//console.log('. USCITO DALLA CHIAMATA !', response);
/* response = await axiosInstance[method](path, {
baseURL,
params: payload,
headers: {
@@ -183,7 +207,8 @@ async function Request(type: string, path: string, payload: any, responsedata =
'x-refrtok': userStore.refreshToken,
},
...responsedata,
});
});*/
} else if (type === 'postFormData') {
response = await axiosInstance.post(path, payload, config);
} else {
@@ -191,15 +216,19 @@ async function Request(type: string, path: string, payload: any, responsedata =
}
// Gestione aggiornamento token se necessario
const setAuthToken = (path === '/updatepwd' || path === '/users/login');
if (response && response.status === 200 && (setAuthToken || path === '/users/login')) {
const setAuthToken = path === '/updatepwd' || path === '/users/login';
if (
response &&
response.status === 200 &&
(setAuthToken || path === '/users/login')
) {
const x_auth_token = String(response.headers['x-auth'] || '');
const refreshToken = String(response.headers['x-refrtok'] || '');
if (!x_auth_token) {
userStore.setServerCode(toolsext.ERR_AUTHENTICATION);
}
if (setAuthToken) {
userStore.UpdatePwd(x_auth_token, refreshToken);
userStore.updatePwd(x_auth_token, refreshToken);
localStorage.setItem(toolsext.localStorage.token, x_auth_token);
localStorage.setItem(toolsext.localStorage.refreshToken, refreshToken);
}
@@ -213,28 +242,42 @@ async function Request(type: string, path: string, payload: any, responsedata =
return new Types.AxiosSuccess(response.data, response.status);
} catch (error) {
// Aggiornamento asincrono dello stato di connessione (setTimeout per dare tempo a eventuali animazioni)
console.error('Errore funzione Request', error)
setTimeout(() => {
if (['get'].includes(type.toLowerCase())) {
globalStore.connData.downloading_server = (globalStore.connData.downloading_server === 1) ? -1 : globalStore.connData.downloading_server;
globalStore.connData.downloading_server =
globalStore.connData.downloading_server === 1
? -1
: globalStore.connData.downloading_server;
} else {
globalStore.connData.uploading_server = (globalStore.connData.uploading_server === 1) ? -1 : globalStore.connData.uploading_server;
globalStore.connData.downloading_server = (globalStore.connData.downloading_server === 1) ? -1 : globalStore.connData.downloading_server;
globalStore.connData.uploading_server =
globalStore.connData.uploading_server === 1
? -1
: globalStore.connData.uploading_server;
globalStore.connData.downloading_server =
globalStore.connData.downloading_server === 1
? -1
: globalStore.connData.downloading_server;
}
}, 1000);
if (import.meta.env.DEV) {
console.log('ERROR using', path);
console.log('error.response=', error.response);
if (error && error.response) {
console.log('error.response=', JSON.stringify(error.response, null, 2));
}
}
let mycode = 0;
if (error.response) {
const code = error.response.data?.code || 0;
mycode = code;
userStore.setServerCode(mycode);
return Promise.reject(new Types.AxiosError(error.response.status, error.response.data, code));
return Promise.reject(
new Types.AxiosError(error.response.status, error.response.data, code)
);
}
return Promise.reject(new Types.AxiosError(0, null, mycode, error));
}
}
export default Request
export default Request;