mirror of
				https://github.com/mealie-recipes/mealie.git
				synced 2025-10-31 10:13:32 -04:00 
			
		
		
		
	feat: Migrate to Nuxt 3 framework (#5184)
Co-authored-by: Michael Genson <71845777+michael-genson@users.noreply.github.com> Co-authored-by: Kuchenpirat <24235032+Kuchenpirat@users.noreply.github.com>
This commit is contained in:
		
							
								
								
									
										44
									
								
								frontend/plugins/axios.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										44
									
								
								frontend/plugins/axios.ts
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,44 @@ | ||||
| import axios from "axios"; | ||||
| import { alert } from "~/composables/use-toast"; | ||||
|  | ||||
| export default defineNuxtPlugin(() => { | ||||
|   const tokenName = useRuntimeConfig().public.AUTH_TOKEN; | ||||
|   const axiosInstance = axios.create({ | ||||
|     baseURL: "/", // api calls already pass with /api | ||||
|     timeout: 10000, | ||||
|     headers: { | ||||
|       "Content-Type": "application/json", | ||||
|       "Authorization": "Bearer " + useCookie(tokenName).value, | ||||
|     }, | ||||
|     withCredentials: true, | ||||
|   }); | ||||
|  | ||||
|   // Add request interceptor | ||||
|   axiosInstance.interceptors.request.use( | ||||
|     (config) => { | ||||
|       // You can add auth tokens or other headers here | ||||
|       return config; | ||||
|     }, | ||||
|     (error) => { | ||||
|       return Promise.reject(error); | ||||
|     }, | ||||
|   ); | ||||
|  | ||||
|   // Add response interceptor | ||||
|   axiosInstance.interceptors.response.use( | ||||
|     (response) => { | ||||
|       if (response?.data?.message) alert.info(response.data.message as string); | ||||
|       return response; | ||||
|     }, | ||||
|     (error) => { | ||||
|       if (error?.response?.data?.detail?.message) alert.error(error.response.data.detail.message as string); | ||||
|       return Promise.reject(error); | ||||
|     }, | ||||
|   ); | ||||
|  | ||||
|   return { | ||||
|     provide: { | ||||
|       axios: axiosInstance, | ||||
|     }, | ||||
|   }; | ||||
| }); | ||||
		Reference in New Issue
	
	Block a user