11import { redirect } from "next/navigation" ;
22
3+ import dayjs from "dayjs" ;
4+ import relativeTime from "dayjs/plugin/relativeTime" ;
35import { LogoutButton } from "@/components/auth/LogoutButton" ;
46import { createClient } from "@/lib/supabase/server" ;
57import { QUERIES } from "@/lib/supabase/repository" ;
8+ import { Card , CardContent , CardHeader , CardTitle } from "@/components/ui/card" ;
9+ import { Avatar , AvatarFallback , AvatarImage } from "@/components/ui/avatar" ;
10+ import "dayjs/locale/ko" ;
11+
12+ dayjs . extend ( relativeTime ) ;
13+ dayjs . locale ( "ko" ) ;
614
715export default async function Profile ( ) {
816 const supabase = await createClient ( ) ;
@@ -13,16 +21,43 @@ export default async function Profile() {
1321 } = await supabase . auth . getUser ( ) ;
1422 if ( error || ! user ) redirect ( "/auth/login" ) ;
1523
16- const { data : profile } = await QUERIES . getName ( supabase , user . id ) ;
24+ const { data : profile } = await QUERIES . getNameAndPhoto ( supabase , user . id ) ;
25+
26+ const initials = ( profile ?. display_name || ( user . email ?? "" ) )
27+ . slice ( 0 , 2 )
28+ . toUpperCase ( ) ;
1729
1830 return (
19- < div className = "flex w-full items-center justify-center gap-2" >
20- < p >
21- 안녕하세요 < span > { profile ?. display_name ?? "" } 님!</ span >
22- < br />
23- 이메일: < span > { user . email } </ span >
24- </ p >
25- < LogoutButton />
31+ < div className = "mx-auto flex w-full max-w-xl items-center justify-center p-4" >
32+ < Card className = "w-full" >
33+ < CardHeader className = "flex flex-row items-center gap-4" >
34+ < Avatar className = "h-12 w-12" >
35+ { profile ?. photo_url ? (
36+ < AvatarImage
37+ src = { profile . photo_url }
38+ alt = { profile ?. display_name ?? "" }
39+ />
40+ ) : null }
41+ < AvatarFallback > { initials } </ AvatarFallback >
42+ </ Avatar >
43+ < div className = "flex flex-col" >
44+ < CardTitle className = "text-xl" >
45+ { profile ?. display_name ?? "이름 없는 사용자" }
46+ </ CardTitle >
47+ < span className = "text-muted-foreground text-sm" > { user . email } </ span >
48+ </ div >
49+ < div className = "ml-auto" >
50+ < LogoutButton />
51+ </ div >
52+ </ CardHeader >
53+ < CardContent >
54+ < div className = "text-muted-foreground text-end text-sm" >
55+ 함께한 지{ " " }
56+ { profile ?. created_at ? dayjs ( profile . created_at ) . fromNow ( true ) : "" } { " " }
57+ 되었어요
58+ </ div >
59+ </ CardContent >
60+ </ Card >
2661 </ div >
2762 ) ;
2863}
0 commit comments