-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathpage.tsx
More file actions
129 lines (110 loc) Β· 3.5 KB
/
Copy pathpage.tsx
File metadata and controls
129 lines (110 loc) Β· 3.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
'use client';
import { useEffect } from 'react';
import { useSearchParams } from 'next/navigation';
import { useTranslations } from 'next-intl';
import { css } from '_panda/css';
import { Button } from '@gitanimals/ui-panda';
import { login } from '@/components/AuthButton';
import { buildDesktopCallbackUrl, isValidDesktopRedirect } from '@/constants/desktopAuth';
import { useClientSession } from '@/utils/clientAuth';
export default function DesktopAuthPage() {
const params = useSearchParams();
const redirectUri = params.get('redirect_uri');
const state = params.get('state');
const errorCode = params.get('error');
const t = useTranslations('Auth');
const { status, data } = useClientSession();
const isValid = isValidDesktopRedirect(redirectUri) && !!state;
useEffect(() => {
if (!isValid) return;
if (status === 'authenticated' && data?.user?.accessToken) {
window.location.replace(buildDesktopCallbackUrl(redirectUri!, data.user.accessToken, state!));
}
}, [status, isValid, redirectUri, state, data?.user?.accessToken]);
if (!isValid) {
return (
<div className={pageRootCss}>
<div className={cardCss}>
<h1 className={titleCss}>μλͺ»λ μμ²</h1>
<p className={descCss}>redirect_uriκ° νμ© λ²μλ₯Ό λ²μ΄λ¬κ±°λ νμ νλΌλ―Έν°κ° λλ½λμμ΅λλ€.</p>
</div>
</div>
);
}
const handleLogin = () => {
login(`/auth/desktop?redirect_uri=${encodeURIComponent(redirectUri!)}&state=${encodeURIComponent(state!)}`);
};
return (
<div className={pageRootCss}>
<div className={cardCss}>
<h1 className={titleCss}>{t('desktopTitle')}</h1>
{errorCode && <div className={errorBannerCss}>{t('desktopErrorBanner')}</div>}
{status === 'loading' && <p className={loadingTextCss}>{t('desktopLoadingMessage')}</p>}
{status === 'authenticated' && <p className={loadingTextCss}>{t('desktopAuthenticatedMessage')}</p>}
{status === 'unauthenticated' && (
<>
<p className={descCss}>{t('desktopDescription')}</p>
<Button variant="primary" size="m" onClick={handleLogin}>
{t('desktopContinueButton')}
</Button>
</>
)}
</div>
</div>
);
}
const pageRootCss = css({
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
justifyContent: 'center',
minHeight: '100vh',
padding: '24px',
bg: 'linear-gradient(180deg, #000 0%, #004875 38.51%, #005B93 52.46%, #006FB3 73.8%, #0187DB 100%)',
color: 'white',
_mobile: {
padding: '16px',
},
});
const cardCss = css({
borderRadius: '16px',
background: 'rgba(255, 255, 255, 0.1)',
backdropFilter: 'blur(7px)',
padding: '40px',
width: 'fit-content',
minWidth: '520px',
maxWidth: '100%',
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
gap: '16px',
_mobile: {
minWidth: '100%',
padding: '24px 16px',
background: 'rgba(255, 255, 255, 0.08)',
},
});
const titleCss = css({
textStyle: 'glyph28.bold',
color: 'white',
_mobile: { textStyle: 'glyph24.bold' },
});
const loadingTextCss = css({
textStyle: 'glyph20.regular',
color: 'white.white_70',
});
const descCss = css({
textStyle: 'glyph16.regular',
color: 'white.white_80',
textAlign: 'center',
whiteSpace: 'pre-line',
});
const errorBannerCss = css({
width: '100%',
padding: '12px 16px',
borderRadius: '8px',
background: 'rgba(255, 75, 75, 0.15)',
color: 'white',
textStyle: 'glyph14.regular',
textAlign: 'center',
});