From fb059cfe7f73372f98dafcc42aaa1d30cadfccd8 Mon Sep 17 00:00:00 2001 From: Altay Date: Tue, 12 Dec 2023 11:31:32 +0300 Subject: [PATCH] feat: make app-header work with authentication --- app/(auth)/sign-in/page.tsx | 2 +- components/layout/app-header.tsx | 98 +++++++++++-------- components/layout/app-layout.tsx | 26 ++++- .../theme-provider/radix-themes.provider.tsx | 2 +- components/ui/unstyled-button.tsx | 18 ++++ 5 files changed, 101 insertions(+), 45 deletions(-) create mode 100644 components/ui/unstyled-button.tsx diff --git a/app/(auth)/sign-in/page.tsx b/app/(auth)/sign-in/page.tsx index dcdfd59..8b4ac5a 100644 --- a/app/(auth)/sign-in/page.tsx +++ b/app/(auth)/sign-in/page.tsx @@ -13,7 +13,7 @@ export default function Page() {
- diff --git a/components/layout/app-header.tsx b/components/layout/app-header.tsx index c0de3ca..33704c2 100644 --- a/components/layout/app-header.tsx +++ b/components/layout/app-header.tsx @@ -1,7 +1,19 @@ import { ArrowRightIcon, PersonIcon } from '@radix-ui/react-icons'; -import { Avatar, Button, DropdownMenu, Flex, Text } from '@radix-ui/themes'; +import { + Avatar, + Button, + DropdownMenuContent, + DropdownMenuItem, + DropdownMenuLabel, + DropdownMenuRoot, + DropdownMenuSeparator, + DropdownMenuTrigger, + Flex, + Text, +} from '@radix-ui/themes'; import Link from 'next/link'; +import { UnstyledButton } from '../ui/unstyled-button'; import { AppContent } from './app-content'; import { AppHeaderLogo } from './app-header-logo'; @@ -22,52 +34,60 @@ function AppHeaderActionsAuthenticated( props: Pick, 'user'>, ) { return ( - - - - {props.user.username} - + + + } + radius="full" + src={props.user.avatarURL} + /> + - - {props.user.credits === 0 ? 'No' : props.user.credits} credits - remaining - - + + + + + {props.user.username} + - - - } - radius="full" - src={props.user.avatarURL} - /> - + + {props.user.credits === 0 ? 'No' : props.user.credits} credits + remaining + + + - - Buy credits - Settings - - Sign out - - - + + + Your episodes + Settings + + + + + + Sign out + + + + ); } function AppHeaderActionsGuest() { return ( - - - - - + ); } diff --git a/components/layout/app-layout.tsx b/components/layout/app-layout.tsx index a66eaa4..7ec44e9 100644 --- a/components/layout/app-layout.tsx +++ b/components/layout/app-layout.tsx @@ -1,12 +1,32 @@ import type { PropsWithChildren } from 'react'; +import { fetchAccount } from '@/lib/services/account'; +import { getIsAuthenticated } from '@/lib/services/supabase/auth'; import { Box, Flex } from '@radix-ui/themes'; import { AppContent } from './app-content'; import { AppFooter } from './app-footer'; import { AppHeader } from './app-header'; -export function AppLayout({ children }: PropsWithChildren) { +export async function AppLayout({ children }: PropsWithChildren) { + let appHeader = ; + const isAuthenticated = await getIsAuthenticated(); + + if (isAuthenticated) { + const account = await fetchAccount(); + + appHeader = ( + + ); + } + return ( -
- -
+
{appHeader}
diff --git a/components/theme-provider/radix-themes.provider.tsx b/components/theme-provider/radix-themes.provider.tsx index e136bbe..9ad1e57 100644 --- a/components/theme-provider/radix-themes.provider.tsx +++ b/components/theme-provider/radix-themes.provider.tsx @@ -4,7 +4,7 @@ import { Theme } from '@radix-ui/themes'; export function RadixThemesProvider({ children }: PropsWithChildren) { return ( - + {children} ); diff --git a/components/ui/unstyled-button.tsx b/components/ui/unstyled-button.tsx new file mode 100644 index 0000000..eb8b46a --- /dev/null +++ b/components/ui/unstyled-button.tsx @@ -0,0 +1,18 @@ +import type { ComponentProps } from 'react'; + +export function UnstyledButton(props: ComponentProps<'button'>) { + return ( +