.
This commit is contained in:
1 parent
5af2c80cd1
commit
f7ee34da4f
78 files changed
+9016
-150
No files matched your search
+41
-9
@@ -1,11 +1,38 @@
|
||||
import { BrowserRouter, Link, Route, Routes } from 'react-router';
|
||||
import { useMsal } from '@azure/msal-react';
|
||||
import DevAuthSwitcher from './components/DevAuthSwitcher';
|
||||
import { DEFAULT_COMMUNITY_ID } from './config';
|
||||
import { useCommunity } from './api/hooks';
|
||||
import { isMsalConfigured } from './lib/auth/msal.config';
|
||||
import AuthCallbackPage from './pages/AuthCallback';
|
||||
import HomePage from './pages/HomePage';
|
||||
import LoginPage from './pages/Login';
|
||||
import MatchDetailPage from './pages/MatchDetailPage';
|
||||
import AuctionPage from './pages/AuctionPage';
|
||||
|
||||
function MsalHeaderActions() {
|
||||
const { accounts, instance } = useMsal();
|
||||
const account = instance.getActiveAccount() ?? accounts[0];
|
||||
|
||||
if (!account) {
|
||||
return (
|
||||
<Link className="btn btn-primary btn-xs px-3" to="/login">
|
||||
로그인
|
||||
</Link>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<button
|
||||
type="button"
|
||||
className="btn btn-ghost btn-xs px-3"
|
||||
onClick={() => void instance.logoutRedirect()}
|
||||
>
|
||||
{account.name ?? account.username} 로그아웃
|
||||
</button>
|
||||
);
|
||||
}
|
||||
|
||||
function App() {
|
||||
const communityQuery = useCommunity(DEFAULT_COMMUNITY_ID);
|
||||
const communityLabel = communityQuery.data?.name ?? 'LOLYMPUS';
|
||||
@@ -21,20 +48,25 @@ function App() {
|
||||
>
|
||||
{communityLabel}
|
||||
</Link>
|
||||
{DEFAULT_COMMUNITY_ID ? (
|
||||
<span className="text-[10px] uppercase tracking-wider text-base-content/25">
|
||||
API Live
|
||||
</span>
|
||||
) : (
|
||||
<span className="text-[10px] uppercase tracking-wider text-amber-500/70">
|
||||
Set `VITE_DEFAULT_COMMUNITY_ID`
|
||||
</span>
|
||||
)}
|
||||
<div className="flex items-center gap-3">
|
||||
{DEFAULT_COMMUNITY_ID ? (
|
||||
<span className="text-[10px] uppercase tracking-wider text-base-content/25">
|
||||
API Live
|
||||
</span>
|
||||
) : (
|
||||
<span className="text-[10px] uppercase tracking-wider text-amber-500/70">
|
||||
Set `VITE_DEFAULT_COMMUNITY_ID`
|
||||
</span>
|
||||
)}
|
||||
{isMsalConfigured && <MsalHeaderActions />}
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<Routes>
|
||||
<Route path="/" element={<HomePage />} />
|
||||
<Route path="/login" element={<LoginPage />} />
|
||||
<Route path="/auth/callback" element={<AuthCallbackPage />} />
|
||||
<Route path="/match/:id" element={<MatchDetailPage />} />
|
||||
<Route path="/match/:id/auction" element={<AuctionPage />} />
|
||||
</Routes>
|
||||
|
||||
@@ -68,6 +68,7 @@ export interface ApiRiotAccount {
|
||||
export interface ApiUser {
|
||||
_id: string;
|
||||
communityId: string;
|
||||
identityId?: string;
|
||||
role: CommunityRole;
|
||||
kakaoTalkId?: string;
|
||||
kakaoTalkNickname?: string;
|
||||
@@ -198,8 +199,22 @@ export interface ApiAuction {
|
||||
updatedAt: string;
|
||||
}
|
||||
|
||||
export interface ApiIdentity {
|
||||
id: string;
|
||||
entraOid: string;
|
||||
tenantId?: string;
|
||||
email?: string;
|
||||
displayName?: string;
|
||||
}
|
||||
|
||||
export interface ApiMembership {
|
||||
user: ApiUser;
|
||||
community: ApiCommunity | null;
|
||||
}
|
||||
|
||||
export interface MeResponse {
|
||||
user: ApiUser | null;
|
||||
identity: ApiIdentity | null;
|
||||
memberships: ApiMembership[];
|
||||
}
|
||||
|
||||
export interface MatchesResponse {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { useEffect, useRef, useState } from 'react';
|
||||
import { io, type Socket } from 'socket.io-client';
|
||||
import { API_BASE_URL, useAuthUserId } from '../config';
|
||||
import { acquireAccessToken } from '../lib/auth/token-provider';
|
||||
import type { ApiAuction, Position, TeamSide } from './types';
|
||||
|
||||
type ConnectionStatus =
|
||||
@@ -31,37 +32,53 @@ export function useAuctionSocket(matchId: string | undefined) {
|
||||
return;
|
||||
}
|
||||
|
||||
const socket = io(`${API_BASE_URL}/auction`, {
|
||||
transports: ['websocket'],
|
||||
auth: authUserId ? { 'x-auth-user-id': authUserId } : {},
|
||||
});
|
||||
|
||||
socketRef.current = socket;
|
||||
let disposed = false;
|
||||
setConnectionStatus('connecting');
|
||||
setError(null);
|
||||
|
||||
socket.on('connect', () => {
|
||||
setConnectionStatus('connected');
|
||||
socket.emit('join', { matchId });
|
||||
});
|
||||
void (async () => {
|
||||
const accessToken = await acquireAccessToken().catch((error) => {
|
||||
console.warn('Failed to acquire socket access token:', error);
|
||||
return null;
|
||||
});
|
||||
if (disposed) return;
|
||||
|
||||
socket.on('disconnect', () => {
|
||||
setConnectionStatus('disconnected');
|
||||
});
|
||||
const socket = io(`${API_BASE_URL}/auction`, {
|
||||
transports: ['websocket'],
|
||||
auth: accessToken
|
||||
? { token: accessToken }
|
||||
: authUserId
|
||||
? { 'x-auth-user-id': authUserId }
|
||||
: {},
|
||||
});
|
||||
|
||||
socket.on('state', (nextAuction: ApiAuction) => {
|
||||
setAuction(nextAuction);
|
||||
setError(null);
|
||||
});
|
||||
socketRef.current = socket;
|
||||
|
||||
socket.on('error', (payload: { message?: string }) => {
|
||||
setConnectionStatus('error');
|
||||
setError(payload.message ?? '실시간 경매 연결 중 오류가 발생했습니다.');
|
||||
});
|
||||
socket.on('connect', () => {
|
||||
setConnectionStatus('connected');
|
||||
socket.emit('join', { matchId });
|
||||
});
|
||||
|
||||
socket.on('disconnect', () => {
|
||||
setConnectionStatus('disconnected');
|
||||
});
|
||||
|
||||
socket.on('state', (nextAuction: ApiAuction) => {
|
||||
setAuction(nextAuction);
|
||||
setError(null);
|
||||
});
|
||||
|
||||
socket.on('error', (payload: { message?: string }) => {
|
||||
setConnectionStatus('error');
|
||||
setError(payload.message ?? '실시간 경매 연결 중 오류가 발생했습니다.');
|
||||
});
|
||||
})();
|
||||
|
||||
return () => {
|
||||
socket.removeAllListeners();
|
||||
socket.disconnect();
|
||||
disposed = true;
|
||||
const socket = socketRef.current;
|
||||
socket?.removeAllListeners();
|
||||
socket?.disconnect();
|
||||
socketRef.current = null;
|
||||
setConnectionStatus('idle');
|
||||
};
|
||||
|
||||
@@ -36,12 +36,14 @@ function subscribeToWindowChanges(eventName: string, callback: () => void) {
|
||||
}
|
||||
|
||||
export function getAuthUserId(): string | null {
|
||||
if (!import.meta.env.DEV) return null;
|
||||
if (typeof window === 'undefined') return null;
|
||||
const value = window.localStorage.getItem(AUTH_USER_ID_STORAGE_KEY)?.trim();
|
||||
return value ? value : null;
|
||||
}
|
||||
|
||||
export function setAuthUserId(userId: string | null) {
|
||||
if (!import.meta.env.DEV) return;
|
||||
if (typeof window === 'undefined') return;
|
||||
|
||||
if (!userId?.trim()) {
|
||||
|
||||
@@ -3,6 +3,7 @@ import { createRoot } from 'react-dom/client';
|
||||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
||||
import './index.css';
|
||||
import App from './App.tsx';
|
||||
import { MsalAppProvider } from './lib/auth/MsalAppProvider.tsx';
|
||||
|
||||
const queryClient = new QueryClient({
|
||||
defaultOptions: {
|
||||
@@ -16,8 +17,10 @@ const queryClient = new QueryClient({
|
||||
|
||||
createRoot(document.getElementById('root')!).render(
|
||||
<StrictMode>
|
||||
<QueryClientProvider client={queryClient}>
|
||||
<App />
|
||||
</QueryClientProvider>
|
||||
<MsalAppProvider>
|
||||
<QueryClientProvider client={queryClient}>
|
||||
<App />
|
||||
</QueryClientProvider>
|
||||
</MsalAppProvider>
|
||||
</StrictMode>,
|
||||
);
|
||||
@@ -8,7 +8,11 @@ import {
|
||||
type AuctionStateView,
|
||||
} from '../api/mappers';
|
||||
import { useAuctionSocket } from '../api/useAuctionSocket';
|
||||
import { DEFAULT_COMMUNITY_ID, setDevCaptainSide, useDevCaptainSide } from '../config';
|
||||
import {
|
||||
DEFAULT_COMMUNITY_ID,
|
||||
setDevCaptainSide,
|
||||
useDevCaptainSide,
|
||||
} from '../config';
|
||||
import { ApiError } from '../lib/api';
|
||||
import { positionIcon, positionLabel } from '../lib/league';
|
||||
import type { Position } from '../api/types';
|
||||
@@ -395,6 +399,10 @@ function BidLog({ bids }: { bids: AuctionStateView['bids'] }) {
|
||||
export default function AuctionPage() {
|
||||
const { id } = useParams();
|
||||
const meQuery = useMe();
|
||||
const currentUser =
|
||||
meQuery.data?.memberships.find(
|
||||
(membership) => membership.community?._id === DEFAULT_COMMUNITY_ID,
|
||||
)?.user ?? null;
|
||||
const matchQuery = useMatch(id, DEFAULT_COMMUNITY_ID);
|
||||
const auctionQuery = useAuction(id, DEFAULT_COMMUNITY_ID);
|
||||
const socket = useAuctionSocket(id);
|
||||
@@ -460,8 +468,8 @@ export default function AuctionPage() {
|
||||
|
||||
const canManageAuction =
|
||||
import.meta.env.DEV ||
|
||||
meQuery.data?.user?.role === 'owner' ||
|
||||
meQuery.data?.user?.role === 'admin';
|
||||
currentUser?.role === 'owner' ||
|
||||
currentUser?.role === 'admin';
|
||||
const phaseLabel: Record<AuctionStateView['phase'], string> = {
|
||||
waiting: '경매 준비 중...',
|
||||
presenting: '다음 선수 등장',
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
import { useEffect } from 'react';
|
||||
import { useNavigate } from 'react-router';
|
||||
|
||||
export default function AuthCallbackPage() {
|
||||
const navigate = useNavigate();
|
||||
|
||||
useEffect(() => {
|
||||
const timer = window.setTimeout(() => navigate('/', { replace: true }), 300);
|
||||
return () => window.clearTimeout(timer);
|
||||
}, [navigate]);
|
||||
|
||||
return (
|
||||
<main className="max-w-5xl mx-auto px-4 sm:px-6 py-20 text-center">
|
||||
<span className="text-sm text-base-content/45">로그인 처리 중...</span>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
import { useMsal } from '@azure/msal-react';
|
||||
import {
|
||||
isMsalConfigured,
|
||||
MSAL_API_SCOPE,
|
||||
msalInstance,
|
||||
} from '../lib/auth/msal.config';
|
||||
|
||||
function LoginButton() {
|
||||
const { instance } = useMsal();
|
||||
|
||||
return (
|
||||
<button
|
||||
type="button"
|
||||
className="btn btn-primary btn-sm px-5"
|
||||
onClick={() => void instance.loginRedirect({ scopes: [MSAL_API_SCOPE] })}
|
||||
>
|
||||
Microsoft로 로그인
|
||||
</button>
|
||||
);
|
||||
}
|
||||
|
||||
export default function LoginPage() {
|
||||
return (
|
||||
<main className="max-w-5xl mx-auto px-4 sm:px-6 py-20">
|
||||
<div className="max-w-md border border-base-content/10 bg-base-100 p-6 shadow-sm">
|
||||
<h1 className="text-xl font-bold tracking-tight">로그인</h1>
|
||||
<p className="mt-2 text-sm text-base-content/50">
|
||||
Microsoft Entra ID 계정으로 로그인하면 LOLYMPUS 멤버십을 불러옵니다.
|
||||
</p>
|
||||
<div className="mt-5">
|
||||
{isMsalConfigured && msalInstance ? (
|
||||
<LoginButton />
|
||||
) : (
|
||||
<div className="text-sm text-amber-600">
|
||||
MSAL 환경변수 설정이 필요합니다.
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
@@ -281,6 +281,11 @@ export default function MatchDetailPage() {
|
||||
const authUserId = useAuthUserId();
|
||||
const matchQuery = useMatch(id, DEFAULT_COMMUNITY_ID);
|
||||
const meQuery = useMe();
|
||||
const currentUser =
|
||||
meQuery.data?.memberships.find(
|
||||
(membership) => membership.community?._id === DEFAULT_COMMUNITY_ID,
|
||||
)?.user ?? null;
|
||||
const canUseMemberActions = Boolean(currentUser || authUserId);
|
||||
const auctionQuery = useAuction(id, DEFAULT_COMMUNITY_ID);
|
||||
const [blueCaptainUserId, setBlueCaptainUserId] = useState('');
|
||||
const [redCaptainUserId, setRedCaptainUserId] = useState('');
|
||||
@@ -291,8 +296,8 @@ export default function MatchDetailPage() {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({
|
||||
preferredPositions:
|
||||
meQuery.data?.user?.preferredPositions.length
|
||||
? meQuery.data.user.preferredPositions.slice(0, 5)
|
||||
currentUser?.preferredPositions.length
|
||||
? currentUser.preferredPositions.slice(0, 5)
|
||||
: buildDefaultPreferredPositions(),
|
||||
}),
|
||||
}),
|
||||
@@ -376,7 +381,7 @@ export default function MatchDetailPage() {
|
||||
const match = mapApiMatchToMatchDetail(matchQuery.data);
|
||||
const si = statusBadge(match.status);
|
||||
const canManageAuction =
|
||||
meQuery.data?.user?.role === 'owner' || meQuery.data?.user?.role === 'admin';
|
||||
currentUser?.role === 'owner' || currentUser?.role === 'admin';
|
||||
const auctionNotStarted =
|
||||
auctionQuery.error instanceof ApiError && auctionQuery.error.status === 404;
|
||||
const showAuctionLink = Boolean(auctionQuery.data);
|
||||
@@ -490,7 +495,7 @@ export default function MatchDetailPage() {
|
||||
participants={match.participants}
|
||||
maxParticipants={match.maxParticipants}
|
||||
joined={match.joined}
|
||||
canJoin={Boolean(authUserId)}
|
||||
canJoin={canUseMemberActions}
|
||||
onJoin={() => joinMatchMutation.mutate()}
|
||||
isJoining={joinMatchMutation.isPending}
|
||||
/>
|
||||
@@ -551,9 +556,9 @@ export default function MatchDetailPage() {
|
||||
>
|
||||
{startAuctionMutation.isPending ? '시작 중...' : '경매 시작'}
|
||||
</button>
|
||||
{!authUserId && (
|
||||
{!canUseMemberActions && (
|
||||
<span className="text-xs text-amber-600">
|
||||
Dev Auth에 owner/admin User ID를 먼저 입력해주세요.
|
||||
로그인 또는 Dev Auth에 owner/admin User ID를 먼저 입력해주세요.
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
|
||||
Reference in new issue
Block a user