|
| 1 | +'use client'; |
| 2 | + |
| 3 | +import { useEffect } from 'react'; |
| 4 | +import { useSearchParams } from 'next/navigation'; |
| 5 | +import { css } from '_panda/css'; |
| 6 | + |
| 7 | +import { login } from '@/components/AuthButton'; |
| 8 | +import { buildDesktopCallbackUrl, isValidDesktopRedirect } from '@/constants/desktopAuth'; |
| 9 | +import { useClientSession } from '@/utils/clientAuth'; |
| 10 | + |
| 11 | +export default function DesktopAuthPage() { |
| 12 | + const params = useSearchParams(); |
| 13 | + const redirectUri = params.get('redirect_uri'); |
| 14 | + const state = params.get('state'); |
| 15 | + |
| 16 | + const { status, data } = useClientSession(); |
| 17 | + |
| 18 | + const isValid = isValidDesktopRedirect(redirectUri) && !!state; |
| 19 | + |
| 20 | + useEffect(() => { |
| 21 | + if (!isValid) return; |
| 22 | + |
| 23 | + if (status === 'authenticated' && data?.user?.accessToken) { |
| 24 | + window.location.replace(buildDesktopCallbackUrl(redirectUri!, data.user.accessToken, state!)); |
| 25 | + } else if (status === 'unauthenticated') { |
| 26 | + login( |
| 27 | + `/auth/desktop?redirect_uri=${encodeURIComponent(redirectUri!)}&state=${encodeURIComponent(state!)}`, |
| 28 | + ); |
| 29 | + } |
| 30 | + }, [status, isValid, redirectUri, state, data?.user?.accessToken]); |
| 31 | + |
| 32 | + if (!isValid) { |
| 33 | + return ( |
| 34 | + <div className={pageRootCss}> |
| 35 | + <div className={cardCss}> |
| 36 | + <h1 className={titleCss}>잘못된 요청</h1> |
| 37 | + <p className={descCss}> |
| 38 | + redirect_uri가 허용 범위를 벗어났거나 필수 파라미터가 누락되었습니다. |
| 39 | + </p> |
| 40 | + </div> |
| 41 | + </div> |
| 42 | + ); |
| 43 | + } |
| 44 | + |
| 45 | + const message = |
| 46 | + status === 'authenticated' ? '데스크톱 앱으로 이동합니다…' : '로그인으로 이동합니다…'; |
| 47 | + |
| 48 | + return ( |
| 49 | + <div className={pageRootCss}> |
| 50 | + <div className={cardCss}> |
| 51 | + <p className={loadingTextCss}>{message}</p> |
| 52 | + </div> |
| 53 | + </div> |
| 54 | + ); |
| 55 | +} |
| 56 | + |
| 57 | +const pageRootCss = css({ |
| 58 | + display: 'flex', |
| 59 | + flexDirection: 'column', |
| 60 | + alignItems: 'center', |
| 61 | + justifyContent: 'center', |
| 62 | + minHeight: '100vh', |
| 63 | + padding: '24px', |
| 64 | + bg: 'linear-gradient(180deg, #000 0%, #004875 38.51%, #005B93 52.46%, #006FB3 73.8%, #0187DB 100%)', |
| 65 | + color: 'white', |
| 66 | + _mobile: { |
| 67 | + padding: '16px', |
| 68 | + }, |
| 69 | +}); |
| 70 | + |
| 71 | +const cardCss = css({ |
| 72 | + borderRadius: '16px', |
| 73 | + background: 'rgba(255, 255, 255, 0.1)', |
| 74 | + backdropFilter: 'blur(7px)', |
| 75 | + padding: '40px', |
| 76 | + width: 'fit-content', |
| 77 | + minWidth: '520px', |
| 78 | + maxWidth: '100%', |
| 79 | + display: 'flex', |
| 80 | + flexDirection: 'column', |
| 81 | + alignItems: 'center', |
| 82 | + gap: '16px', |
| 83 | + _mobile: { |
| 84 | + minWidth: '100%', |
| 85 | + padding: '24px 16px', |
| 86 | + background: 'rgba(255, 255, 255, 0.08)', |
| 87 | + }, |
| 88 | +}); |
| 89 | + |
| 90 | +const titleCss = css({ |
| 91 | + textStyle: 'glyph28.bold', |
| 92 | + color: 'white', |
| 93 | + _mobile: { textStyle: 'glyph24.bold' }, |
| 94 | +}); |
| 95 | + |
| 96 | +const loadingTextCss = css({ |
| 97 | + textStyle: 'glyph20.regular', |
| 98 | + color: 'white.white_70', |
| 99 | +}); |
| 100 | + |
| 101 | +const descCss = css({ |
| 102 | + textStyle: 'glyph16.regular', |
| 103 | + color: 'white.white_80', |
| 104 | + textAlign: 'center', |
| 105 | +}); |
0 commit comments