From af136ea914436fe0b5ae977cd43bf9b5772c8d21 Mon Sep 17 00:00:00 2001 From: Roman Kyslyy Date: Tue, 2 Jul 2024 18:01:11 +0300 Subject: [PATCH] Refactor --- web/app/layout.tsx | 6 ++--- web/app/lib/ui/WebHeader/WebHeader.tsx | 15 +++++++++++ web/app/lib/ui/WebHeader/WebNavigation.tsx | 25 +++++++++++++++++++ .../lib/ui/Greet.tsx | 0 .../page.tsx | 0 web/middleware.ts | 2 +- 6 files changed, 43 insertions(+), 5 deletions(-) create mode 100644 web/app/lib/ui/WebHeader/WebHeader.tsx create mode 100644 web/app/lib/ui/WebHeader/WebNavigation.tsx rename web/app/{sample-protected-route => sample-protected-page}/lib/ui/Greet.tsx (100%) rename web/app/{sample-protected-route => sample-protected-page}/page.tsx (100%) diff --git a/web/app/layout.tsx b/web/app/layout.tsx index 6abef73..db662d0 100644 --- a/web/app/layout.tsx +++ b/web/app/layout.tsx @@ -4,7 +4,7 @@ import './globals.css' import SessionWrapper from './lib/providers/SessionProvider' import { ApolloClientProvider } from './lib/providers/ApolloClientProvider' import clsx from 'clsx' -import { Authentication } from './lib/ui/Authentication/Authentication' +import { WebHeader } from './lib/ui/WebHeader/WebHeader' const inter = Inter({ subsets: ['latin'] }) @@ -24,9 +24,7 @@ export default function RootLayout({
-
- -
+ {children}
diff --git a/web/app/lib/ui/WebHeader/WebHeader.tsx b/web/app/lib/ui/WebHeader/WebHeader.tsx new file mode 100644 index 0000000..8c2b6c3 --- /dev/null +++ b/web/app/lib/ui/WebHeader/WebHeader.tsx @@ -0,0 +1,15 @@ +import { auth } from '@/auth' +import { Authentication } from '../Authentication/Authentication' +import { WebNavigation } from './WebNavigation' + +export const WebHeader = async () => { + const session = await auth() + + return ( +
+ {session?.user ? : null} + + +
+ ) +} diff --git a/web/app/lib/ui/WebHeader/WebNavigation.tsx b/web/app/lib/ui/WebHeader/WebNavigation.tsx new file mode 100644 index 0000000..8a2216f --- /dev/null +++ b/web/app/lib/ui/WebHeader/WebNavigation.tsx @@ -0,0 +1,25 @@ +'use client' + +import Link from 'next/link' +import { usePathname } from 'next/navigation' + +export const WebNavigation = () => { + const pathname = usePathname() + + let url: string + let text: string + + if (pathname === '/') { + url = '/sample-protected-page' + text = 'Sample Protected Page' + } else { + url = '/' + text = 'Home Page' + } + + return ( + + {text} + + ) +} diff --git a/web/app/sample-protected-route/lib/ui/Greet.tsx b/web/app/sample-protected-page/lib/ui/Greet.tsx similarity index 100% rename from web/app/sample-protected-route/lib/ui/Greet.tsx rename to web/app/sample-protected-page/lib/ui/Greet.tsx diff --git a/web/app/sample-protected-route/page.tsx b/web/app/sample-protected-page/page.tsx similarity index 100% rename from web/app/sample-protected-route/page.tsx rename to web/app/sample-protected-page/page.tsx diff --git a/web/middleware.ts b/web/middleware.ts index 6af5741..4a59eb0 100644 --- a/web/middleware.ts +++ b/web/middleware.ts @@ -6,5 +6,5 @@ export default NextAuth(authConfig).auth export const config = { // require login for these paths // https://nextjs.org/docs/app/building-your-application/routing/middleware - matcher: ['/sample-protected-route/:path'], + matcher: ['/sample-protected-page/:path'], }