diff --git a/apps/website/src/app/(with-auth)/@routeIndicator/dashboard/page.tsx b/apps/website/src/app/(with-auth)/@routeIndicator/dashboard/page.tsx new file mode 100644 index 0000000..c7b49ab --- /dev/null +++ b/apps/website/src/app/(with-auth)/@routeIndicator/dashboard/page.tsx @@ -0,0 +1,48 @@ +import { createServerComponentClient } from '@supabase/auth-helpers-nextjs'; +import type { NextPage } from 'next'; +import { cookies } from 'next/headers'; +import { InAppHeaderRouteIndicatorDivider, InAppHeaderRouteIndicatorIcon, InAppHeaderRouteIndicatorLabel } from '#website/layout/global/header'; +import { findUserUseCase } from '#website/use-case/find-user'; +import { findUserLostItemsUseCase } from '~website/src/use-case/find-user-lost-items'; + +const RouteIndicator: NextPage = async () => { + const cookieStore = cookies(); + + const supabase = createServerComponentClient({ cookies: () => cookieStore }); + const { + data: { user }, + } = await supabase.auth.getUser(); + if (!user) { + return null; + } + + const foundUser = await findUserUseCase(user.id); + if (!foundUser) { + return null; + } + + const userLostItem = await findUserLostItemsUseCase(foundUser.authId); + if (!userLostItem) { + return null; + } + + return userLostItem.currentTargetLostItem && foundUser.lostAndFoundState !== 'NONE' ? ( + <> + + {!!userLostItem.currentTargetLostItem.lostItem.imageUrls[0] && ( + + )} + {userLostItem.currentTargetLostItem.lostItem.title} + + ) : ( + <> + + Overview + + ); +}; + +export default RouteIndicator; diff --git a/apps/website/src/app/(with-auth)/@routeIndicator/default.tsx b/apps/website/src/app/(with-auth)/@routeIndicator/default.tsx new file mode 100644 index 0000000..f74aed4 --- /dev/null +++ b/apps/website/src/app/(with-auth)/@routeIndicator/default.tsx @@ -0,0 +1,5 @@ +import type { ReactNode } from 'react'; + +const RouteIndicatorPage = (): ReactNode => null; + +export default RouteIndicatorPage; diff --git a/apps/website/src/app/(with-auth)/@routeIndicator/report/page.tsx b/apps/website/src/app/(with-auth)/@routeIndicator/report/page.tsx new file mode 100644 index 0000000..f74aed4 --- /dev/null +++ b/apps/website/src/app/(with-auth)/@routeIndicator/report/page.tsx @@ -0,0 +1,5 @@ +import type { ReactNode } from 'react'; + +const RouteIndicatorPage = (): ReactNode => null; + +export default RouteIndicatorPage; diff --git a/apps/website/src/app/(with-auth)/@routeIndicator/search/page.tsx b/apps/website/src/app/(with-auth)/@routeIndicator/search/page.tsx new file mode 100644 index 0000000..f74aed4 --- /dev/null +++ b/apps/website/src/app/(with-auth)/@routeIndicator/search/page.tsx @@ -0,0 +1,5 @@ +import type { ReactNode } from 'react'; + +const RouteIndicatorPage = (): ReactNode => null; + +export default RouteIndicatorPage; diff --git a/apps/website/src/app/(with-auth)/layout.tsx b/apps/website/src/app/(with-auth)/layout.tsx index 198a808..97e9085 100644 --- a/apps/website/src/app/(with-auth)/layout.tsx +++ b/apps/website/src/app/(with-auth)/layout.tsx @@ -1,16 +1,35 @@ +import { createServerComponentClient } from '@supabase/auth-helpers-nextjs'; import type { NextPage } from 'next'; +import { cookies } from 'next/headers'; import type { ReactNode } from 'react'; +import { InAppHeader } from '#website/layout/global/header'; import { AuthGuardProvider } from '#website/layout/with-auth/auth-guard-provider'; +import { findUserUseCase } from '#website/use-case/find-user'; type WithAuthLayoutProps = { children: ReactNode; + routeIndicator: ReactNode; }; -const WithAuthLayout: NextPage = ({ children }) => ( - <> - - {children} - -); +const WithAuthLayout: NextPage = async ({ children, routeIndicator }) => { + // HACK: To avoid next build errors, functions that depend on async contexts need to be called outside the function that creates the new execution context. + // ref: https://nextjs.org/docs/messages/dynamic-server-error + const cookieStore = cookies(); + + const supabase = createServerComponentClient({ cookies: () => cookieStore }); + const { + data: { user }, + } = await supabase.auth.getUser(); + + const foundUser = user && (await findUserUseCase(user.id)); + + return ( + <> + {routeIndicator} + + {children} + + ); +}; export default WithAuthLayout; diff --git a/apps/website/src/app/json-ld.ts b/apps/website/src/app/(with-no-auth)/json-ld.ts similarity index 100% rename from apps/website/src/app/json-ld.ts rename to apps/website/src/app/(with-no-auth)/json-ld.ts diff --git a/apps/website/src/app/(with-no-auth)/layout.tsx b/apps/website/src/app/(with-no-auth)/layout.tsx new file mode 100644 index 0000000..0b0ae34 --- /dev/null +++ b/apps/website/src/app/(with-no-auth)/layout.tsx @@ -0,0 +1,32 @@ +import { createServerComponentClient } from '@supabase/auth-helpers-nextjs'; +import type { NextPage } from 'next'; +import { cookies } from 'next/headers'; +import type { ReactNode } from 'react'; +import { Header } from '#website/layout/global/header'; +import { findUserUseCase } from '#website/use-case/find-user'; + +type WithNoAuthLayoutProps = { + children: ReactNode; +}; + +const WithNoAuthLayout: NextPage = async ({ children }) => { + // HACK: To avoid next build errors, functions that depend on async contexts need to be called outside the function that creates the new execution context. + // ref: https://nextjs.org/docs/messages/dynamic-server-error + const cookieStore = cookies(); + + const supabase = createServerComponentClient({ cookies: () => cookieStore }); + const { + data: { user }, + } = await supabase.auth.getUser(); + + const foundUser = user && (await findUserUseCase(user.id)); + + return ( + <> +
+ {children} + + ); +}; + +export default WithNoAuthLayout; diff --git a/apps/website/src/app/page.tsx b/apps/website/src/app/(with-no-auth)/page.tsx similarity index 100% rename from apps/website/src/app/page.tsx rename to apps/website/src/app/(with-no-auth)/page.tsx diff --git a/apps/website/src/app/layout.tsx b/apps/website/src/app/layout.tsx index c40586d..a177c2d 100644 --- a/apps/website/src/app/layout.tsx +++ b/apps/website/src/app/layout.tsx @@ -4,55 +4,37 @@ import { firaCode, getFontVariables, notoSans } from '@lockerai/core/font/family import { getBaseUrl } from '@lockerai/core/util/get-base-url'; import { colors } from '@lockerai/design-token'; import { cn } from '@lockerai/tailwind'; -import { createServerComponentClient } from '@supabase/auth-helpers-nextjs'; import type { Metadata, NextPage, Viewport } from 'next'; -import { cookies } from 'next/headers'; import type { ReactNode } from 'react'; import { UrqlProvider } from '#website/infra/urql/ssr'; import { Footer } from '#website/layout/global/footer'; -import { Header } from '#website/layout/global/header'; -import { findUserUseCase } from '#website/use-case/find-user'; import '#website/style/global.css'; type RootLayoutProps = { children: ReactNode; }; -const RootLayout: NextPage = async ({ children }) => { - // HACK: To avoid next build errors, functions that depend on async contexts need to be called outside the function that creates the new execution context. - // ref: https://nextjs.org/docs/messages/dynamic-server-error - const cookieStore = cookies(); - - const supabase = createServerComponentClient({ cookies: () => cookieStore }); - const { - data: { user }, - } = await supabase.auth.getUser(); - - const foundUser = user && (await findUserUseCase(user.id)); - - return ( - - - -
- - -
- {children} -