Updated frameworks.

This commit is contained in:
Eric Gullickson
2025-08-25 12:40:27 -05:00
parent e22d643ae3
commit 0cdb9803de
25 changed files with 5366 additions and 41 deletions

View File

@@ -44,9 +44,11 @@ const TokenInjector: React.FC<{ children: React.ReactNode }> = ({ children }) =>
const { getAccessTokenSilently, isAuthenticated } = useAuth0();
React.useEffect(() => {
let interceptorId: number | undefined;
if (isAuthenticated) {
// Add token to all API requests
apiClient.interceptors.request.use(async (config) => {
interceptorId = apiClient.interceptors.request.use(async (config) => {
try {
const token = await getAccessTokenSilently();
config.headers.Authorization = `Bearer ${token}`;
@@ -56,6 +58,13 @@ const TokenInjector: React.FC<{ children: React.ReactNode }> = ({ children }) =>
return config;
});
}
// Cleanup function to remove interceptor
return () => {
if (interceptorId !== undefined) {
apiClient.interceptors.request.eject(interceptorId);
}
};
}, [isAuthenticated, getAccessTokenSilently]);
return <>{children}</>;