update
This commit is contained in:
32
src/modules/query.ts
Normal file
32
src/modules/query.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
'use client';
|
||||
import { QueryClient } from '@kevisual/query';
|
||||
import { QueryLoginBrowser } from '@kevisual/api/login';
|
||||
import { toast } from 'sonner';
|
||||
|
||||
// Only create instances in browser environment
|
||||
const isBrowser = typeof window !== 'undefined';
|
||||
|
||||
export const query = isBrowser ? new QueryClient({}) : {} as QueryClient;
|
||||
|
||||
export const queryLogin = isBrowser
|
||||
? new QueryLoginBrowser({
|
||||
query: query as any,
|
||||
})
|
||||
: {} as QueryLoginBrowser;
|
||||
|
||||
if (isBrowser) {
|
||||
(query as any).afterResponse = async (res, ctx) => {
|
||||
const newRes = await queryLogin.run401Action(res, ctx, {
|
||||
afterAlso401: () => {},
|
||||
afterCheck: (res: any) => {
|
||||
if (res.code === 200) {
|
||||
toast.success('刷新登陆信息');
|
||||
setTimeout(() => {
|
||||
window.location.reload();
|
||||
}, 2000);
|
||||
}
|
||||
},
|
||||
});
|
||||
return newRes as any;
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user