@workspace 
import axios, {
  AxiosError,
  AxiosResponse,
  InternalAxiosRequestConfig,
} from "axios";
// import { dynamicPaths, staticPaths } from '../../constants'
// import { getItemFromStorage } from '@/utils/localstorage'
const url = "api/home";
const Axios = axios.create({
  baseURL: url
    ? process.env.NEXT_PUBLIC_BASE_URL
    : process.env.NEXT_PUBLIC_BASE_LOCAL_URL,
  headers: {
    "Content-Type": "application/json",
  },
});

// function publicRoutes(pathname: string): boolean {
//   return (
//       staticPaths.includes(pathname) ||
//       dynamicPaths.some(path => pathname.startsWith(path))
//   )
// }

Axios.interceptors.request.use(
  async (config: InternalAxiosRequestConfig) => {
    // const accessToken = getItemFromStorage('accessToken')
    // config.headers.Authorization = accessToken ? `Bearer ${accessToken}` : ''
    return config;
  },
  (error: AxiosError) => Promise.reject(error),
);

Axios.interceptors.response.use(
  (response: AxiosResponse) => response,
  async (error: AxiosError) => {
    // const currentPath =
    //   typeof window !== 'undefined' ? window.location.pathname : ''

    // if (!publicRoutes(currentPath)) {
    //   if (error.response?.status === 401) {
    //     if (typeof window !== 'undefined') {
    //       window.location.href = '/accept_invitation'
    //       window.location.reload()
    //     }
    //   } else if (error.response?.status === 403) {
    //     if (typeof window !== 'undefined') {
    //       window.location.href = '/'
    //     }
    //   } else if (
    //       error.response?.status >= 400 &&
    //       error.response.status <= 500
    //   ) {
    //     const message = error.response.data.message
    //     if (message && message.length > 0) {
    //     }
    //   }
    // }

    return Promise.reject(error);
  },
);

export default Axios;

// export const handleRefresh = async () => {
//   const refreshToken = getCookie('refreshToken');
//   try {
//     const response = await Axios.post(
//       baseURL + '/' + 'identity/AccountApi/RefreshToken',
//       { refreshToken },
//     );
//     setCookie('accessToken', response?.data.data.access_token, {
//       maxAge: 60 * 60 * 24 * 30, // 30 days
//       path: '/',
//       secure: process.env.NODE_ENV === 'production', // set to true only in production
//       sameSite: 'lax', // change to 'lax' if you're making cross-site requests
//       httpOnly: false, // set to false if you need to access it in your JS code
//     });
//     setCookie('accessToken', response?.data.data.refresh_token, {
//       maxAge: 60 * 60 * 24 * 30, // 30 days
//       path: '/',
//       secure: process.env.NODE_ENV === 'production', // set to true only in production
//       sameSite: 'lax', // change to 'lax' if you're making cross-site requests
//       httpOnly: false, // set to false if you need to access it in your JS code
//     });
//     Axios.defaults.headers.common['Authorization'] =
//       `Bearer ${response?.data.data.access_token}`;
//     return true; // Token refresh was successful
//   } catch (error) {
//     deleteCookie('accessToken');
//     return false;
//   }
// };

how to use the refresh token properly so with 401 403 error it refreshes the token and also use the exp in current accesstoken and at its exp the refresh happens and the new accesstoken persists on cookie do it like a senior developer in nextjs 14 app router