23 lines
720 B
TypeScript
23 lines
720 B
TypeScript
import { Query, DataOpts } from '@kevisual/query';
|
|
import { QueryLoginBrowser } from '@kevisual/api/query-login'
|
|
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 = useContextKey('queryClient', new Query({
|
|
url: '/client/router',
|
|
}));
|
|
|
|
queryClient.after(afterResponse);
|
|
export const queryLogin = useContextKey('queryLogin', new QueryLoginBrowser({
|
|
query: query
|
|
})); |