Fix form keyboard issues and sticky footers in agent screens
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
import type { AxiosError, AxiosInstance } from 'axios';
|
||||
|
||||
import { secureStorage } from '../storage/secureStorage';
|
||||
|
||||
const unauthorizedHandlers = new Set<() => void>();
|
||||
|
||||
export const registerUnauthorizedHandler = (handler: () => void) => {
|
||||
unauthorizedHandlers.add(handler);
|
||||
|
||||
return () => {
|
||||
unauthorizedHandlers.delete(handler);
|
||||
};
|
||||
};
|
||||
|
||||
export const attachInterceptors = (client: AxiosInstance) => {
|
||||
client.interceptors.request.use(async (config) => {
|
||||
const token = await secureStorage.getAccessToken();
|
||||
|
||||
if (token) {
|
||||
const nextHeaders = (config.headers ?? {}) as Record<string, string>;
|
||||
nextHeaders.Authorization = `Bearer ${token}`;
|
||||
config.headers = nextHeaders as never;
|
||||
}
|
||||
|
||||
return config;
|
||||
});
|
||||
|
||||
client.interceptors.response.use(
|
||||
(response) => response,
|
||||
async (error: AxiosError) => {
|
||||
if (error.response?.status === 401) {
|
||||
await secureStorage.clearSession();
|
||||
unauthorizedHandlers.forEach((handler) => handler());
|
||||
}
|
||||
|
||||
return Promise.reject(error);
|
||||
},
|
||||
);
|
||||
};
|
||||
Reference in New Issue
Block a user