обработка перелогина при оплате без мерцания
All checks were successful
Deploy / CreateImage (push) Successful in 5m48s
Deploy / DeployService (push) Successful in 22s

This commit is contained in:
Nastya 2025-07-17 12:10:00 +03:00
parent 3c444a3837
commit 1169a6644c
4 changed files with 21 additions and 8 deletions

@ -2,3 +2,4 @@
. "$(dirname -- "$0")/_/husky.sh"
yarn eslint . --fix
yarn type-check

@ -5,6 +5,10 @@
"scripts": {
"start": "NODE_OPTIONS=\"--max-old-space-size=1024\" craco start",
"build": "craco build",
"build:check": "tsc --noEmit && craco build",
"type-check": "tsc --noEmit",
"type-check:strict": "tsc --noEmit --strict --noImplicitAny --noImplicitReturns --noImplicitThis --noUnusedLocals --noUnusedParameters",
"pre-commit": "npm run type-check",
"test": "craco test --env=node --transformIgnorePatterns \"node_modules/(?!@frontend)/\"",
"test:cart": "vitest ./src/utils/calcCart",
"eject": "craco eject",

@ -6,29 +6,30 @@ import { clearTickets } from '@root/stores/tickets';
import { clearUserData, useUserStore } from '@root/stores/user';
import { useEffect } from 'react';
import { useLocation } from 'react-router-dom';
export const useReauthorization = () => {
const userId = useUserStore(store => store.userId)
const { search } = useLocation();
useEffect(() => {
// Этот эффект сработает при каждом изменении query-параметров
const params = new URLSearchParams(search);
const URLuserId = params.get('userId');
const URLuserId = params.get('userid');
const URLtoken = params.get('sec');
if (URLuserId !== userId && URLtoken) {
if (getAuthToken()) {
// Если есть токен в URL, устанавливаем его
// Очищаем данные только если токен действительно изменился
if (getAuthToken() !== URLtoken) {
clearAuthToken();
clearUserData();
clearCustomTariffs();
clearTickets();
setNotEnoughMoneyAmount(0)
logout();
setNotEnoughMoneyAmount(0);
// Не вызываем logout() чтобы избежать перенаправления
}
setAuthToken(URLtoken);//перелогиниваемся
setAuthToken(URLtoken);
}
}, [search]);
};

@ -16,7 +16,14 @@
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react-jsx"
"jsx": "react-jsx",
"noImplicitAny": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"exactOptionalPropertyTypes": true,
"noPropertyAccessFromIndexSignature": true
},
"include": ["src", "**/*.ts"]
}