2021-07-31 15:57:43 +00:00
|
|
|
import { Suspense } from "react";
|
2021-07-31 14:33:18 +00:00
|
|
|
import {
|
|
|
|
AppProps,
|
|
|
|
ErrorBoundary,
|
|
|
|
ErrorComponent,
|
|
|
|
AuthenticationError,
|
|
|
|
AuthorizationError,
|
|
|
|
ErrorFallbackProps,
|
|
|
|
useQueryErrorResetBoundary,
|
2021-07-31 15:57:43 +00:00
|
|
|
} from "blitz";
|
2021-07-31 14:33:18 +00:00
|
|
|
|
2021-07-31 15:57:43 +00:00
|
|
|
import LoginForm from "../auth/components/login-form";
|
2021-07-31 14:33:18 +00:00
|
|
|
|
2021-07-31 15:57:43 +00:00
|
|
|
import "app/core/styles/index.css";
|
2021-07-31 14:33:18 +00:00
|
|
|
|
|
|
|
export default function App({ Component, pageProps }: AppProps) {
|
2021-07-31 15:57:43 +00:00
|
|
|
const getLayout = Component.getLayout || ((page) => page);
|
2021-07-31 14:33:18 +00:00
|
|
|
|
|
|
|
return (
|
2021-08-01 14:03:49 +00:00
|
|
|
<ErrorBoundary FallbackComponent={RootErrorFallback} onReset={useQueryErrorResetBoundary().reset}>
|
|
|
|
<Suspense fallback="Silence, ca pousse">{getLayout(<Component {...pageProps} />)}</Suspense>
|
2021-07-31 14:33:18 +00:00
|
|
|
</ErrorBoundary>
|
2021-07-31 15:57:43 +00:00
|
|
|
);
|
2021-07-31 14:33:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function RootErrorFallback({ error, resetErrorBoundary }: ErrorFallbackProps) {
|
|
|
|
if (error instanceof AuthenticationError) {
|
2021-07-31 15:57:43 +00:00
|
|
|
return <LoginForm onSuccess={resetErrorBoundary} />;
|
2021-07-31 14:33:18 +00:00
|
|
|
} else if (error instanceof AuthorizationError) {
|
2021-08-01 14:03:49 +00:00
|
|
|
return <ErrorComponent statusCode={error.statusCode} title="Sorry, you are not authorized to access this" />;
|
2021-07-31 14:33:18 +00:00
|
|
|
} else {
|
2021-08-01 14:03:49 +00:00
|
|
|
return <ErrorComponent statusCode={error.statusCode || 400} title={error.message || error.name} />;
|
2021-07-31 14:33:18 +00:00
|
|
|
}
|
|
|
|
}
|