diff --git a/package.json b/package.json index 382c85f..3a9958e 100644 --- a/package.json +++ b/package.json @@ -55,6 +55,6 @@ "tailwindcss": "^4.2.0", "tw-animate-css": "^1.4.0", "typescript": "^5.9.3", - "vite": "v8.0.0-beta.14" + "vite": "v8.0.0-beta.15" } } \ No newline at end of file diff --git a/src/modules/query.ts b/src/modules/query.ts index 0c773ca..471126a 100644 --- a/src/modules/query.ts +++ b/src/modules/query.ts @@ -1,13 +1,23 @@ -import { Query } from '@kevisual/query'; +import { Query, DataOpts } from '@kevisual/query'; import { QueryLoginBrowser } from '@kevisual/api/query-login' -export const query = new Query({ +import { useContextKey } from '@kevisual/context'; +export const query = useContextKey('query', new Query({ url: '/api/router', -}); +})); +const afterResponse: DataOpts['afterResponse'] = async (response, ctx) => { + if (response.code === 401) { + await queryLogin.logout(); + setTimeout(() => { location.reload() }, 2000); + } + return response; +} +query.after(afterResponse); -export const queryClient = new Query({ +export const queryClient = useContextKey('queryClient', new Query({ url: '/client/router', -}); +})); -export const queryLogin = new QueryLoginBrowser({ +queryClient.after(afterResponse); +export const queryLogin = useContextKey('queryLogin', new QueryLoginBrowser({ query: query -}); \ No newline at end of file +})); \ No newline at end of file diff --git a/src/pages/auth/index.tsx b/src/pages/auth/index.tsx index 041ff38..afa034a 100644 --- a/src/pages/auth/index.tsx +++ b/src/pages/auth/index.tsx @@ -15,7 +15,7 @@ export const AuthProvider = ({ children, mustLogin }: Props) => { useEffect(() => { store.init() }, []) - const loginUrl = '/root/login?redirect=' + encodeURIComponent(window.location.href); + const loginUrl = '/root/login/?redirect=' + encodeURIComponent(window.location.href); if (mustLogin && !store.me) { return (
请先登录以继续访问此页面