22
33import { useEffect } from 'react' ;
44import { useSearchParams } from 'next/navigation' ;
5+ import { useTranslations } from 'next-intl' ;
6+ import { Button } from '@gitanimals/ui-tailwind' ;
57
68import { login } from '@/components/AuthButton' ;
79import { buildDesktopCallbackUrl , isValidDesktopRedirect } from '@/constants/desktopAuth' ;
@@ -16,43 +18,60 @@ export default function DesktopAuthPage() {
1618 const params = useSearchParams ( ) ;
1719 const redirectUri = params . get ( 'redirect_uri' ) ;
1820 const state = params . get ( 'state' ) ;
21+ const errorCode = params . get ( 'error' ) ;
22+ const t = useTranslations ( 'Auth' ) ;
1923
2024 const { status, data } = useClientSession ( ) ;
2125
2226 const isValid = isValidDesktopRedirect ( redirectUri ) && ! ! state ;
2327
2428 useEffect ( ( ) => {
2529 if ( ! isValid ) return ;
26-
2730 if ( status === 'authenticated' && data ?. user ?. accessToken ) {
2831 window . location . replace ( buildDesktopCallbackUrl ( redirectUri ! , data . user . accessToken , state ! ) ) ;
29- } else if ( status === 'unauthenticated' ) {
30- login (
31- `/auth/desktop?redirect_uri=${ encodeURIComponent ( redirectUri ! ) } &state=${ encodeURIComponent ( state ! ) } ` ,
32- ) ;
3332 }
3433 } , [ status , isValid , redirectUri , state , data ?. user ?. accessToken ] ) ;
3534
3635 if ( ! isValid ) {
3736 return (
3837 < div className = { pageRootClass } >
3938 < div className = { cardClass } >
40- < h1 className = "glyph28-bold text-white mobile:glyph24-bold" > 잘못된 요청</ h1 >
41- < p className = "glyph16-regular text-center text-white" >
42- redirect_uri가 허용 범위를 벗어났거나 필수 파라미터가 누락되었습니다.
43- </ p >
39+ < h1 className = "glyph28-bold text-white mobile:glyph24-bold" > { t ( 'desktopInvalidTitle' ) } </ h1 >
40+ < p className = "glyph16-regular text-center text-white-75" > { t ( 'desktopInvalidDescription' ) } </ p >
4441 </ div >
4542 </ div >
4643 ) ;
4744 }
4845
49- const message =
50- status === 'authenticated' ? '데스크톱 앱으로 이동합니다…' : '로그인으로 이동합니다…' ;
46+ const handleLogin = ( ) => {
47+ login ( `/auth/desktop?redirect_uri=${ encodeURIComponent ( redirectUri ! ) } &state=${ encodeURIComponent ( state ! ) } ` ) ;
48+ } ;
5149
5250 return (
5351 < div className = { pageRootClass } >
5452 < div className = { cardClass } >
55- < p className = "glyph20-regular text-white" > { message } </ p >
53+ < h1 className = "glyph28-bold text-white mobile:glyph24-bold" > { t ( 'desktopTitle' ) } </ h1 >
54+
55+ { errorCode && (
56+ < div className = "w-full rounded-[8px] bg-[rgba(255,75,75,0.15)] px-[16px] py-[12px] text-center glyph14-regular text-white" >
57+ { t ( 'desktopErrorBanner' ) }
58+ </ div >
59+ ) }
60+
61+ { status === 'loading' && < p className = "glyph20-regular text-white-75" > { t ( 'desktopLoadingMessage' ) } </ p > }
62+
63+ { status === 'authenticated' && (
64+ < p className = "glyph20-regular text-white-75" > { t ( 'desktopAuthenticatedMessage' ) } </ p >
65+ ) }
66+
67+ { status === 'unauthenticated' && (
68+ < >
69+ < p className = "whitespace-pre-line text-center glyph16-regular text-white-75" > { t ( 'desktopDescription' ) } </ p >
70+ < Button variant = "primary" size = "m" onClick = { handleLogin } >
71+ { t ( 'desktopContinueButton' ) }
72+ </ Button >
73+ </ >
74+ ) }
5675 </ div >
5776 </ div >
5877 ) ;
0 commit comments