Merge branch 'PingChuan' into shiy-login
# Conflicts: # app/config/api-config.ts fix: 1. 修复无法加载数据的问题:没有从入口页中进来会缺少数据。 2. 加强后端接口关于token的校验错误和权限校验错误的管理。 feat: 1. 对接后端的数据看板的接口。 2. 将系统设置单独抽出来作为管理员的固定一个入口。
This commit is contained in:
@@ -276,13 +276,29 @@ export async function postgrestGet<T>(endpoint: string, params?: PostgrestParams
|
||||
},
|
||||
queryParams
|
||||
);
|
||||
|
||||
|
||||
if (response.error) {
|
||||
// 🔑 检测令牌过期错误
|
||||
const isTokenExpired = response.error.includes('令牌已过期') ||
|
||||
response.error.includes('令牌') ||
|
||||
response.error.includes('token') ||
|
||||
response.error.includes('expired') ||
|
||||
response.error.includes('认证') ||
|
||||
response.error.includes('未授权');
|
||||
|
||||
if (isTokenExpired && typeof window !== 'undefined') {
|
||||
console.error('🔑 [PostgREST Client - GET] 检测到令牌过期,清除会话并重定向到登录页');
|
||||
localStorage.removeItem('access_token');
|
||||
localStorage.removeItem('user_info');
|
||||
sessionStorage.clear();
|
||||
window.location.href = '/login?expired=true';
|
||||
}
|
||||
|
||||
throw new Error(response.error);
|
||||
}
|
||||
|
||||
|
||||
// 返回数据和响应头
|
||||
return {
|
||||
return {
|
||||
data: response.data as T,
|
||||
headers: response.headers
|
||||
};
|
||||
@@ -421,6 +437,23 @@ export async function postgrestPost<T, D = Record<string, unknown>>(endpoint: st
|
||||
|
||||
if (response.error) {
|
||||
console.error(`POST请求失败: ${response.error}`);
|
||||
|
||||
// 🔑 检测令牌过期错误
|
||||
const isTokenExpired = response.error.includes('令牌已过期') ||
|
||||
response.error.includes('令牌') ||
|
||||
response.error.includes('token') ||
|
||||
response.error.includes('expired') ||
|
||||
response.error.includes('认证') ||
|
||||
response.error.includes('未授权');
|
||||
|
||||
if (isTokenExpired && typeof window !== 'undefined') {
|
||||
console.error('🔑 [PostgREST Client] 检测到令牌过期,清除会话并重定向到登录页');
|
||||
localStorage.removeItem('access_token');
|
||||
localStorage.removeItem('user_info');
|
||||
sessionStorage.clear();
|
||||
window.location.href = '/login?expired=true';
|
||||
}
|
||||
|
||||
throw new Error(response.error);
|
||||
}
|
||||
|
||||
@@ -548,15 +581,31 @@ export async function postgrestPut<T, D extends object>(
|
||||
},
|
||||
queryParams
|
||||
);
|
||||
|
||||
|
||||
if (response.error) {
|
||||
// 🔑 检测令牌过期错误
|
||||
const isTokenExpired = response.error.includes('令牌已过期') ||
|
||||
response.error.includes('令牌') ||
|
||||
response.error.includes('token') ||
|
||||
response.error.includes('expired') ||
|
||||
response.error.includes('认证') ||
|
||||
response.error.includes('未授权');
|
||||
|
||||
if (isTokenExpired && typeof window !== 'undefined') {
|
||||
console.error('🔑 [PostgREST Client - PATCH] 检测到令牌过期,清除会话并重定向到登录页');
|
||||
localStorage.removeItem('access_token');
|
||||
localStorage.removeItem('user_info');
|
||||
sessionStorage.clear();
|
||||
window.location.href = '/login?expired=true';
|
||||
}
|
||||
|
||||
throw new Error(response.error);
|
||||
}
|
||||
|
||||
|
||||
if (!response.data) {
|
||||
throw new Error('更新成功但未返回数据');
|
||||
}
|
||||
|
||||
|
||||
return { data: response.data };
|
||||
} catch (error) {
|
||||
const apiError = handleApiError(error);
|
||||
@@ -595,11 +644,27 @@ export async function postgrestDelete<T>(endpoint: string, params?: PostgrestPar
|
||||
},
|
||||
queryParams
|
||||
);
|
||||
|
||||
|
||||
if (response.error) {
|
||||
// 🔑 检测令牌过期错误
|
||||
const isTokenExpired = response.error.includes('令牌已过期') ||
|
||||
response.error.includes('令牌') ||
|
||||
response.error.includes('token') ||
|
||||
response.error.includes('expired') ||
|
||||
response.error.includes('认证') ||
|
||||
response.error.includes('未授权');
|
||||
|
||||
if (isTokenExpired && typeof window !== 'undefined') {
|
||||
console.error('🔑 [PostgREST Client - DELETE] 检测到令牌过期,清除会话并重定向到登录页');
|
||||
localStorage.removeItem('access_token');
|
||||
localStorage.removeItem('user_info');
|
||||
sessionStorage.clear();
|
||||
window.location.href = '/login?expired=true';
|
||||
}
|
||||
|
||||
throw new Error(response.error);
|
||||
}
|
||||
|
||||
|
||||
return { data: response.data as T };
|
||||
} catch (error) {
|
||||
const apiError = handleApiError(error);
|
||||
|
||||
Reference in New Issue
Block a user