Models, pipelines, users, subscriptions, usage, audit log, ads, and releases still rendered placeholder or duplicated implementations from the earlier admin split. They now read the live back-office API, share one sidebar and console theme, and the license issuer dialog uses the rotated signing key.
297 lines
9.7 KiB
TypeScript
297 lines
9.7 KiB
TypeScript
'use client'
|
|
|
|
// apps/admin/src/app/login/page.tsx
|
|
// D3RO Voice — Admin Console Login (Midnight Glass v2)
|
|
|
|
import { Suspense, useState } from 'react'
|
|
import { Box, Typography, Button, TextField, Alert } from '@mui/material'
|
|
import GoogleIcon from '@mui/icons-material/Google'
|
|
import LockOutlinedIcon from '@mui/icons-material/LockOutlined'
|
|
import { DoubleBezelCard, TactileBadge } from '@d3ro/ui/components/ds'
|
|
import { C, FONT_SANS, FONT_MONO, primaryButtonSx } from '@/lib/console-theme'
|
|
import { getSupabaseBrowserClient } from '@/lib/supabase-browser'
|
|
import { useRouter, useSearchParams } from 'next/navigation'
|
|
|
|
function LoginForm(): React.ReactElement {
|
|
const router = useRouter()
|
|
const searchParams = useSearchParams()
|
|
const redirectPath = searchParams.get('redirect') || '/'
|
|
|
|
const [usernameOrEmail, setUsernameOrEmail] = useState('')
|
|
const [password, setPassword] = useState('')
|
|
const [loading, setLoading] = useState(false)
|
|
const [errorMsg, setErrorMsg] = useState<string | null>(null)
|
|
|
|
const describeLoginError = (errorKey: unknown, retryAfter: unknown): string => {
|
|
if (errorKey === 'rate_limited') {
|
|
const seconds = typeof retryAfter === 'number' && retryAfter > 0 ? retryAfter : null
|
|
return seconds
|
|
? `로그인 시도가 제한되었습니다. ${Math.ceil(seconds / 60)}분 후 다시 시도해주세요.`
|
|
: '로그인 시도가 제한되었습니다. 잠시 후 다시 시도해주세요.'
|
|
}
|
|
if (errorKey === 'invalid_credentials') return '이메일 또는 비밀번호가 올바르지 않습니다.'
|
|
if (errorKey === 'invalid_auth_response' || errorKey === 'admin_auth_unavailable') {
|
|
return '인증 서버 응답이 올바르지 않습니다. 관리자에게 문의해주세요.'
|
|
}
|
|
return '인증에 실패했습니다.'
|
|
}
|
|
|
|
const handleLogin = async (e?: React.FormEvent): Promise<void> => {
|
|
if (e) e.preventDefault()
|
|
if (!usernameOrEmail || !password) {
|
|
setErrorMsg('이메일과 비밀번호를 입력해주세요.')
|
|
return
|
|
}
|
|
if (!usernameOrEmail.includes('@')) {
|
|
setErrorMsg('관리자 이메일 주소로 로그인해주세요. (username 로그인은 지원이 종료되었습니다)')
|
|
return
|
|
}
|
|
|
|
setLoading(true)
|
|
setErrorMsg(null)
|
|
|
|
try {
|
|
const res = await fetch('/api/auth/login', {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({ usernameOrEmail, password }),
|
|
})
|
|
|
|
const data = await res.json()
|
|
|
|
if (!res.ok || !data.success) {
|
|
throw new Error(describeLoginError(data.error, data.retryAfter))
|
|
}
|
|
|
|
// Successful login
|
|
router.push(redirectPath)
|
|
router.refresh()
|
|
} catch (err) {
|
|
setErrorMsg(err instanceof Error ? err.message : '로그인 중 오류가 발생했습니다.')
|
|
} finally {
|
|
setLoading(false)
|
|
}
|
|
}
|
|
|
|
const handleGoogleLogin = async (): Promise<void> => {
|
|
try {
|
|
const supabase = getSupabaseBrowserClient()
|
|
await supabase.auth.signInWithOAuth({
|
|
provider: 'google',
|
|
options: {
|
|
redirectTo: `${window.location.origin}/auth/callback`,
|
|
},
|
|
})
|
|
} catch {
|
|
setErrorMsg('Google OAuth 서비스 연결을 확인해주세요.')
|
|
}
|
|
}
|
|
|
|
return (
|
|
<Box
|
|
sx={{
|
|
display: 'flex',
|
|
alignItems: 'center',
|
|
justifyContent: 'center',
|
|
minHeight: '100vh',
|
|
bgcolor: 'var(--d3-bg-crtGlass)',
|
|
backgroundImage: 'radial-gradient(ellipse 60% 50% at 50% 40%, var(--d3-accent-glow) 0%, transparent 80%)',
|
|
p: 2,
|
|
position: 'relative',
|
|
overflow: 'hidden',
|
|
}}
|
|
>
|
|
{/* Background Grid Pattern */}
|
|
<Box className="bg-grid" sx={{ position: 'absolute', inset: 0, opacity: 0.04, pointerEvents: 'none' }} />
|
|
|
|
<DoubleBezelCard
|
|
bezelPadding="8px"
|
|
innerPadding="36px"
|
|
sx={{
|
|
width: '100%',
|
|
maxWidth: 440,
|
|
boxShadow: '0 25px 60px var(--d3-scrim), 0 0 40px var(--d3-accent-glow)',
|
|
}}
|
|
>
|
|
{/* Brand Header */}
|
|
<Box sx={{ textAlign: 'center', mb: 3.5 }}>
|
|
<Box
|
|
sx={{
|
|
width: 52,
|
|
height: 52,
|
|
borderRadius: '16px',
|
|
background: 'linear-gradient(135deg, var(--d3-tag-cyan) 0%, var(--d3-accent-main) 50%, var(--d3-tag-purple) 100%)',
|
|
display: 'inline-flex',
|
|
alignItems: 'center',
|
|
justifyContent: 'center',
|
|
boxShadow: '0 0 25px var(--d3-accent-glow)',
|
|
mb: 2,
|
|
}}
|
|
>
|
|
<LockOutlinedIcon sx={{ color: 'var(--d3-text-inverse)', fontSize: 28 }} />
|
|
</Box>
|
|
|
|
<Typography
|
|
sx={{
|
|
fontFamily: FONT_SANS,
|
|
fontSize: '22px',
|
|
fontWeight: 600,
|
|
letterSpacing: '-0.02em',
|
|
color: C.bright,
|
|
lineHeight: 1.2,
|
|
}}
|
|
>
|
|
D3RO Voice Admin CRM
|
|
</Typography>
|
|
|
|
<Typography
|
|
sx={{
|
|
fontFamily: FONT_MONO,
|
|
fontSize: '11px',
|
|
color: C.dim,
|
|
letterSpacing: '0.08em',
|
|
mt: 0.5,
|
|
}}
|
|
>
|
|
RESTRICTED ACCESS • SUPER ADMIN CONTROL
|
|
</Typography>
|
|
|
|
<Box sx={{ display: 'flex', justifyContent: 'center', mt: 1.5 }}>
|
|
<TactileBadge ledColor="green" ledPulse tone="success" mono>
|
|
SECURITY SHIELD ACTIVE
|
|
</TactileBadge>
|
|
</Box>
|
|
</Box>
|
|
|
|
{errorMsg && (
|
|
<Alert
|
|
severity="error"
|
|
sx={{
|
|
mb: 2.5,
|
|
bgcolor: 'var(--d3-status-danger)',
|
|
color: 'var(--d3-status-danger)',
|
|
border: '1px solid var(--d3-status-danger)',
|
|
borderRadius: '10px',
|
|
fontFamily: FONT_SANS,
|
|
fontSize: '12px',
|
|
}}
|
|
>
|
|
{errorMsg}
|
|
</Alert>
|
|
)}
|
|
|
|
{/* Login Form */}
|
|
<Box component="form" onSubmit={handleLogin} sx={{ display: 'flex', flexDirection: 'column', gap: 2 }}>
|
|
<TextField
|
|
label="Admin Email"
|
|
type="email"
|
|
value={usernameOrEmail}
|
|
onChange={(e) => setUsernameOrEmail(e.target.value)}
|
|
fullWidth
|
|
size="small"
|
|
required
|
|
autoComplete="email"
|
|
sx={{
|
|
'& .MuiOutlinedInput-root': {
|
|
bgcolor: 'var(--d3-bg-inset-soft)',
|
|
color: C.bright,
|
|
borderRadius: '10px',
|
|
fontFamily: FONT_SANS,
|
|
fontSize: '13px',
|
|
'& fieldset': { borderColor: C.border },
|
|
'&:hover fieldset': { borderColor: C.borderHl },
|
|
'&.Mui-focused fieldset': { borderColor: C.accentLight },
|
|
},
|
|
'& .MuiInputLabel-root': { color: C.dim },
|
|
}}
|
|
/>
|
|
|
|
<TextField
|
|
label="Password"
|
|
type="password"
|
|
value={password}
|
|
onChange={(e) => setPassword(e.target.value)}
|
|
fullWidth
|
|
size="small"
|
|
required
|
|
autoComplete="current-password"
|
|
sx={{
|
|
'& .MuiOutlinedInput-root': {
|
|
bgcolor: 'var(--d3-bg-inset-soft)',
|
|
color: C.bright,
|
|
borderRadius: '10px',
|
|
fontFamily: FONT_SANS,
|
|
fontSize: '13px',
|
|
'& fieldset': { borderColor: C.border },
|
|
'&:hover fieldset': { borderColor: C.borderHl },
|
|
'&.Mui-focused fieldset': { borderColor: C.accentLight },
|
|
},
|
|
'& .MuiInputLabel-root': { color: C.dim },
|
|
}}
|
|
/>
|
|
|
|
<Button
|
|
type="submit"
|
|
variant="contained"
|
|
disabled={loading}
|
|
fullWidth
|
|
sx={{
|
|
...primaryButtonSx,
|
|
py: 1.25,
|
|
mt: 1,
|
|
}}
|
|
>
|
|
{loading ? '인증 중...' : 'Sign In as Super Admin'}
|
|
</Button>
|
|
|
|
<Box sx={{ display: 'flex', alignItems: 'center', gap: 1.5, my: 1 }}>
|
|
<Box sx={{ flex: 1, height: '1px', bgcolor: C.border }} />
|
|
<Typography sx={{ fontFamily: FONT_MONO, fontSize: '10px', color: C.dim }}>
|
|
OR VIA OAUTH
|
|
</Typography>
|
|
<Box sx={{ flex: 1, height: '1px', bgcolor: C.border }} />
|
|
</Box>
|
|
|
|
<Button
|
|
variant="outlined"
|
|
startIcon={<GoogleIcon />}
|
|
onClick={() => void handleGoogleLogin()}
|
|
fullWidth
|
|
sx={{
|
|
borderColor: C.borderHl,
|
|
color: C.bright,
|
|
bgcolor: 'var(--d3-bg-card-soft)',
|
|
borderRadius: '10px',
|
|
fontFamily: FONT_SANS,
|
|
fontSize: '13px',
|
|
fontWeight: 600,
|
|
textTransform: 'none',
|
|
py: 1.1,
|
|
'&:hover': {
|
|
borderColor: C.accentLight,
|
|
bgcolor: 'var(--d3-bg-raised-soft)',
|
|
},
|
|
}}
|
|
>
|
|
Continue with Google OAuth
|
|
</Button>
|
|
</Box>
|
|
|
|
{/* Footer Note */}
|
|
<Box sx={{ mt: 3.5, textAlign: 'center' }}>
|
|
<Typography sx={{ fontFamily: FONT_MONO, fontSize: '10px', color: C.dim }}>
|
|
Protected by D3RO Unified Auth & Session Cookie Cryptography
|
|
</Typography>
|
|
</Box>
|
|
</DoubleBezelCard>
|
|
</Box>
|
|
)
|
|
}
|
|
|
|
export default function AdminLoginPage(): React.ReactElement {
|
|
return (
|
|
<Suspense fallback={<Box sx={{ minHeight: '100vh', bgcolor: 'var(--d3-bg-crtGlass)' }} />}>
|
|
<LoginForm />
|
|
</Suspense>
|
|
)
|
|
}
|