Skip to content
Snippets Groups Projects
Select Git revision
  • fe97780631e8dedaf91b3d5b5dd9af5074f9a245
  • develop default
  • master protected
  • feature/frontend-tests
  • 0.98
  • 0.97
  • 0.96
  • 0.95
  • 0.94
  • 0.93
  • 0.92
  • 0.91
  • 0.90
  • 0.89
  • 0.88
  • 0.87
  • 0.86
  • 0.85
  • 0.84
  • 0.83
  • 0.82
  • 0.81
  • 0.80
  • 0.79
24 results

bundle.js

Blame
  • useFetchInterceptor.tsx 782 B
    import { useEffect } from 'react';
    import { signOut } from 'next-auth/react';
    
    const useFetchInterceptor = () => {
      useEffect(() => {
        const handleResponse = (response: Response) => {
          if (response.status === 401) {
            const currentUrl = window.location.href;
            signOut({ callbackUrl: `/api/auth/signin?error=SessionRequired&callbackUrl=${encodeURIComponent(currentUrl)}` });
          }
          return response;
        };
    
        const originalFetch = global.fetch.bind(global);
    
        global.fetch = async (input: RequestInfo | URL, init?: RequestInit) => {
          const response = await originalFetch(input, init);
          return handleResponse(response);
        };
    
        return () => {
          global.fetch = originalFetch;
        };
      }, []);
    };
    
    export default useFetchInterceptor;