diff --git a/cwd-admin/src/api/http.ts b/cwd-admin/src/api/http.ts index de58b09..fd7f51f 100644 --- a/cwd-admin/src/api/http.ts +++ b/cwd-admin/src/api/http.ts @@ -35,6 +35,20 @@ async function request(method: HttpMethod, path: string, body?: unknown): Pro } if (!res.ok) { const message = data && data.message ? data.message : `请求失败,状态码 ${res.status}`; + if (res.status === 401 && (message === 'Token expired or invalid' || message === 'Unauthorized')) { + localStorage.removeItem('cwd_admin_token'); + if (typeof window !== 'undefined') { + try { + const url = new URL(window.location.href); + url.pathname = '/login'; + url.search = ''; + url.hash = ''; + window.location.href = url.toString(); + } catch { + window.location.href = '/login'; + } + } + } throw new Error(message); } return data as T; diff --git a/docs/guide/getting-started.md b/docs/guide/getting-started.md index d02fad0..c04209c 100644 --- a/docs/guide/getting-started.md +++ b/docs/guide/getting-started.md @@ -21,7 +21,7 @@ | 行写入 | 10 万 | ~2 次/次访问 | 5 万次页面访问 | | 存储 | 5GB | 1-2KB/评论 | 250 万 + 评论 | -**足以满足以下场景:** +**足以满足以下场景:** 对于个人博客或中小型站点来说,免费计划完全够用。 - 日访问量:30,000 - 50,000 次页面加载 - 日评论量:100 - 200 条新评论