-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: ♻️ ヘッダーを認証済みかどうかで切り替えるようにした (#7)
- Loading branch information
Showing
9 changed files
with
141 additions
and
45 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
apps/website/src/app/(with-auth)/@routeIndicator/dashboard/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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' ? ( | ||
<> | ||
<InAppHeaderRouteIndicatorDivider /> | ||
{!!userLostItem.currentTargetLostItem.lostItem.imageUrls[0] && ( | ||
<InAppHeaderRouteIndicatorIcon | ||
src={userLostItem.currentTargetLostItem.lostItem.imageUrls[0]} | ||
alt={`An image of ${userLostItem.currentTargetLostItem.lostItem.title}`} | ||
/> | ||
)} | ||
<InAppHeaderRouteIndicatorLabel>{userLostItem.currentTargetLostItem.lostItem.title}</InAppHeaderRouteIndicatorLabel> | ||
</> | ||
) : ( | ||
<> | ||
<InAppHeaderRouteIndicatorDivider /> | ||
<InAppHeaderRouteIndicatorLabel>Overview</InAppHeaderRouteIndicatorLabel> | ||
</> | ||
); | ||
}; | ||
|
||
export default RouteIndicator; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import type { ReactNode } from 'react'; | ||
|
||
const RouteIndicatorPage = (): ReactNode => null; | ||
|
||
export default RouteIndicatorPage; |
5 changes: 5 additions & 0 deletions
5
apps/website/src/app/(with-auth)/@routeIndicator/report/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import type { ReactNode } from 'react'; | ||
|
||
const RouteIndicatorPage = (): ReactNode => null; | ||
|
||
export default RouteIndicatorPage; |
5 changes: 5 additions & 0 deletions
5
apps/website/src/app/(with-auth)/@routeIndicator/search/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import type { ReactNode } from 'react'; | ||
|
||
const RouteIndicatorPage = (): ReactNode => null; | ||
|
||
export default RouteIndicatorPage; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<WithAuthLayoutProps> = ({ children }) => ( | ||
<> | ||
<AuthGuardProvider /> | ||
{children} | ||
</> | ||
); | ||
const WithAuthLayout: NextPage<WithAuthLayoutProps> = 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 ( | ||
<> | ||
<InAppHeader user={foundUser}>{routeIndicator}</InAppHeader> | ||
<AuthGuardProvider /> | ||
{children} | ||
</> | ||
); | ||
}; | ||
|
||
export default WithAuthLayout; |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<WithNoAuthLayoutProps> = 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 ( | ||
<> | ||
<Header user={foundUser} /> | ||
{children} | ||
</> | ||
); | ||
}; | ||
|
||
export default WithNoAuthLayout; |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters