deleted some commentes
This commit is contained in:
@@ -17,23 +17,23 @@ const processQueue = (error: any, token: string | null = null) => {
|
||||
failedQueue = [];
|
||||
};
|
||||
|
||||
// Request Interceptor (Token ekleme)
|
||||
apiClient.interceptors.request.use((config) => {
|
||||
const token = useAuthStore.getState().token;
|
||||
if (token && config.headers) {
|
||||
config.headers.Authorization = `Bearer ${token}`;
|
||||
}
|
||||
return config;
|
||||
}, (error) => Promise.reject(error));
|
||||
apiClient.interceptors.request.use(
|
||||
(config) => {
|
||||
const token = useAuthStore.getState().token;
|
||||
if (token && config.headers) {
|
||||
config.headers.Authorization = `Bearer ${token}`;
|
||||
}
|
||||
return config;
|
||||
},
|
||||
(error) => Promise.reject(error),
|
||||
);
|
||||
|
||||
// Response Interceptor (Senior Hata Yönetimi)
|
||||
apiClient.interceptors.response.use(
|
||||
(response) => response,
|
||||
async (error) => {
|
||||
const originalRequest = error.config;
|
||||
const status = error.response?.status;
|
||||
|
||||
// 1. 401 Unauthorized & Refresh Token Yönetimi
|
||||
if (status === 401 && !originalRequest._retry) {
|
||||
if (isRefreshing) {
|
||||
return new Promise((resolve, reject) => {
|
||||
@@ -50,16 +50,13 @@ apiClient.interceptors.response.use(
|
||||
isRefreshing = true;
|
||||
|
||||
try {
|
||||
// Sessizce yeni token almayı dene (Zustand içindeki refresh action'ı)
|
||||
const newToken = await useAuthStore.getState().refreshToken();
|
||||
processQueue(null, newToken);
|
||||
originalRequest.headers.Authorization = `Bearer ${newToken}`;
|
||||
return apiClient(originalRequest);
|
||||
} catch (refreshError) {
|
||||
processQueue(refreshError, null);
|
||||
// Refresh de patladıysa kullanıcıyı temizce çıkışa zorla
|
||||
useAuthStore.getState().logout();
|
||||
// SPA dostu yönlendirme: Sayfa yenilemeden custom bir event veya global history ile
|
||||
window.dispatchEvent(new Event("auth:unauthorized"));
|
||||
return Promise.reject(refreshError);
|
||||
} finally {
|
||||
@@ -67,13 +64,12 @@ apiClient.interceptors.response.use(
|
||||
}
|
||||
}
|
||||
|
||||
// 2. 403 Forbidden Yönetimi (Kullanıcıyı haberdar et, akışı durdur)
|
||||
if (status === 403) {
|
||||
window.dispatchEvent(new Event("auth:forbidden"));
|
||||
}
|
||||
|
||||
return Promise.reject(error);
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
export default apiClient;
|
||||
export default apiClient;
|
||||
|
||||
@@ -1,27 +1,28 @@
|
||||
import i18n from 'i18next'
|
||||
import { initReactI18next } from 'react-i18next'
|
||||
import i18n from "i18next";
|
||||
import { initReactI18next } from "react-i18next";
|
||||
|
||||
import en from './locales/en.json'
|
||||
import ru from './locales/ru.json'
|
||||
import tk from './locales/tk.json'
|
||||
import en from "./locales/en.json";
|
||||
import ru from "./locales/ru.json";
|
||||
import tk from "./locales/tk.json";
|
||||
|
||||
export const SUPPORTED_LANGUAGES = ['en', 'ru', 'tk'] as const
|
||||
export type SupportedLanguage = (typeof SUPPORTED_LANGUAGES)[number]
|
||||
export const SUPPORTED_LANGUAGES = ["en", "ru", "tk"] as const;
|
||||
export type SupportedLanguage = (typeof SUPPORTED_LANGUAGES)[number];
|
||||
|
||||
const savedStorage = localStorage.getItem('tbbank-lang')
|
||||
let savedLang: string | null = null
|
||||
const savedStorage = localStorage.getItem("tbbank-lang");
|
||||
let savedLang: string | null = null;
|
||||
|
||||
if (savedStorage) {
|
||||
try {
|
||||
const parsed = JSON.parse(savedStorage)
|
||||
savedLang = parsed.state?.language
|
||||
const parsed = JSON.parse(savedStorage);
|
||||
savedLang = parsed.state?.language;
|
||||
} catch {
|
||||
savedLang = savedStorage
|
||||
savedLang = savedStorage;
|
||||
}
|
||||
}
|
||||
|
||||
const defaultLang: SupportedLanguage =
|
||||
SUPPORTED_LANGUAGES.includes(savedLang as SupportedLanguage) ? (savedLang as SupportedLanguage) : 'en'
|
||||
const defaultLang: SupportedLanguage = SUPPORTED_LANGUAGES.includes(savedLang as SupportedLanguage)
|
||||
? (savedLang as SupportedLanguage)
|
||||
: "en";
|
||||
|
||||
i18n.use(initReactI18next).init({
|
||||
resources: {
|
||||
@@ -30,10 +31,10 @@ i18n.use(initReactI18next).init({
|
||||
tk: { translation: tk },
|
||||
},
|
||||
lng: defaultLang,
|
||||
fallbackLng: 'en',
|
||||
fallbackLng: "tk",
|
||||
interpolation: {
|
||||
escapeValue: false,
|
||||
},
|
||||
})
|
||||
});
|
||||
|
||||
export default i18n
|
||||
export default i18n;
|
||||
|
||||
Reference in New Issue
Block a user