2022-01-05 12:09:51 +00:00
|
|
|
import type { AppProps } from 'next/app';
|
2022-09-16 14:36:53 +00:00
|
|
|
import type { Session } from 'next-auth';
|
2022-11-03 18:48:32 +00:00
|
|
|
import type { NextPage } from 'next';
|
2022-08-04 07:45:22 +00:00
|
|
|
import { SessionProvider } from 'next-auth/react';
|
2022-03-29 15:33:51 +00:00
|
|
|
import { useRouter } from 'next/router';
|
2022-12-20 17:18:58 +00:00
|
|
|
import { Toaster } from '@components/Toaster';
|
2022-10-08 17:54:43 +00:00
|
|
|
import { appWithTranslation } from 'next-i18next';
|
2022-11-03 18:48:32 +00:00
|
|
|
import { ReactElement, ReactNode } from 'react';
|
2022-12-13 21:41:27 +00:00
|
|
|
import micromatch from 'micromatch';
|
2022-12-20 20:11:27 +00:00
|
|
|
import nextI18NextConfig from '../next-i18next.config.js';
|
2022-11-03 18:48:32 +00:00
|
|
|
|
2022-12-30 13:43:50 +00:00
|
|
|
import { AccountLayout, SetupLinkLayout } from '@components/layouts';
|
2023-10-13 05:17:40 +00:00
|
|
|
import '@boxyhq/react-ui/dist/style.css';
|
2022-02-22 19:03:21 +00:00
|
|
|
import '../styles/globals.css';
|
2024-02-27 22:12:39 +00:00
|
|
|
import { BUIProvider } from '@boxyhq/internal-ui';
|
2022-01-05 12:09:51 +00:00
|
|
|
|
2022-11-03 18:48:32 +00:00
|
|
|
const unauthenticatedRoutes = [
|
|
|
|
'/',
|
|
|
|
'/admin/auth/login',
|
2023-02-07 12:30:37 +00:00
|
|
|
'/admin/auth/idp-login',
|
2022-11-03 18:48:32 +00:00
|
|
|
'/well-known/saml-configuration',
|
2023-12-13 18:23:37 +00:00
|
|
|
'/well-known/oidc-configuration',
|
2022-12-18 21:13:12 +00:00
|
|
|
'/well-known/idp-configuration',
|
2022-11-03 18:48:32 +00:00
|
|
|
'/oauth/jwks',
|
|
|
|
'/idp/select',
|
|
|
|
'/error',
|
2022-12-23 22:43:04 +00:00
|
|
|
'/well-known',
|
2022-11-03 18:48:32 +00:00
|
|
|
];
|
|
|
|
|
2022-12-13 21:41:27 +00:00
|
|
|
const isUnauthenticatedRoute = (pathname: string) => {
|
|
|
|
return micromatch.isMatch(pathname, unauthenticatedRoutes);
|
|
|
|
};
|
|
|
|
|
2022-11-03 18:48:32 +00:00
|
|
|
function MyApp({ Component, pageProps }: AppPropsWithLayout) {
|
2024-02-27 22:12:39 +00:00
|
|
|
const router = useRouter();
|
|
|
|
const { pathname } = router;
|
2022-03-29 15:33:51 +00:00
|
|
|
|
2022-11-03 18:48:32 +00:00
|
|
|
const { session, ...props } = pageProps;
|
|
|
|
|
|
|
|
const getLayout = Component.getLayout;
|
|
|
|
|
|
|
|
// If a page level layout exists, use it
|
|
|
|
if (getLayout) {
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
{getLayout(<Component {...props} />)}
|
2022-12-20 17:18:58 +00:00
|
|
|
<Toaster />
|
2022-11-03 18:48:32 +00:00
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-12-13 21:41:27 +00:00
|
|
|
if (pathname.startsWith('/setup/')) {
|
|
|
|
return (
|
2022-12-30 13:43:50 +00:00
|
|
|
<SetupLinkLayout>
|
2022-12-13 21:41:27 +00:00
|
|
|
<Component {...props} />
|
2022-12-20 17:18:58 +00:00
|
|
|
<Toaster />
|
2022-12-30 13:43:50 +00:00
|
|
|
</SetupLinkLayout>
|
2022-12-13 21:41:27 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isUnauthenticatedRoute(pathname)) {
|
2022-11-03 18:48:32 +00:00
|
|
|
return <Component {...props} />;
|
2022-03-29 15:33:51 +00:00
|
|
|
}
|
|
|
|
|
2022-02-22 19:03:21 +00:00
|
|
|
return (
|
2024-02-27 22:12:39 +00:00
|
|
|
<BUIProvider value={{ router }}>
|
|
|
|
<SessionProvider session={session}>
|
|
|
|
<AccountLayout>
|
|
|
|
<Component {...props} />
|
|
|
|
<Toaster />
|
|
|
|
</AccountLayout>
|
|
|
|
</SessionProvider>
|
|
|
|
</BUIProvider>
|
2022-02-22 19:03:21 +00:00
|
|
|
);
|
2022-01-05 12:09:51 +00:00
|
|
|
}
|
|
|
|
|
2022-12-20 20:11:27 +00:00
|
|
|
export default appWithTranslation<never>(MyApp, nextI18NextConfig);
|
2022-11-03 18:48:32 +00:00
|
|
|
|
|
|
|
export type AppPropsWithLayout = AppProps & {
|
|
|
|
Component: NextPageWithLayout;
|
|
|
|
pageProps: {
|
|
|
|
session?: Session;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
export type NextPageWithLayout<P = Record<string, unknown>> = NextPage<P> & {
|
|
|
|
getLayout?: (page: ReactElement) => ReactNode;
|
|
|
|
};
|