feat: enhance afterResponse handling for 401 status and ensure async logout
This commit is contained in:
@@ -1,22 +1,23 @@
|
||||
import { Query } from '@kevisual/query';
|
||||
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',
|
||||
|
||||
}));
|
||||
query.afterResponse = async (response, ctx) => {
|
||||
const afterResponse: DataOpts['afterResponse'] = async (response, ctx) => {
|
||||
if (response.code === 401) {
|
||||
queryLogin.logout();
|
||||
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
|
||||
}));
|
||||
Reference in New Issue
Block a user