feat : BBS 7번 메뉴 로그인/로그아웃 및 로그인 화면 추가
SpecialSource Frontend (React) CD / deploy (push) Successful in 11s

- 로그인 전 '로그인', 로그인 후 '로그아웃'으로 표시, 단축키 L
- 로그인 화면에서 ID/PW 입력 → POST /api/login (개발 시 localhost:8080)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
headporterandClaude Opus 5.5 committed 2026-11-17 14:58:08 +09:00
1 parent d925a1599d
commit 2a09fa80a9
7 files changed
+92 -12

No files matched your search

+6 -2
View File
@@ -4,6 +4,7 @@ import { useEffect, useReducer, useRef, useState, useSyncExternalStore } from "r
import { PALETTE_KEY, PALETTES } from "../constants";
import { execute, initialState } from "../lib/command";
import type { Nav, Palette } from "../types";
import LoginForm from "./LoginForm";
import MainMenu from "./MainMenu";
import PaletteSwitch from "./PaletteSwitch";
import PostDetail from "./PostDetail";
@@ -82,11 +83,14 @@ export default function BbsTerminal() {
<div className={styles.frame}>
<div className={styles.titlebar}>
<span>SPECIALSOURCE-BBS</span>
<span>{state.loggedIn ? "ONLINE: 7 · admin 접속중" : "ONLINE: 6 · 비로그인"}</span>
<span>{state.user ? `ONLINE: 7 · ${state.user} 접속중` : "ONLINE: 6 · 비로그인"}</span>
</div>
<div className={styles.screen}>
{state.screen === "main" && <MainMenu readIds={state.readIds} onSelect={submitFromClick} />}
{state.screen === "main" && (
<MainMenu readIds={state.readIds} loggedIn={!!state.user} onSelect={submitFromClick} />
)}
{state.screen === "login" && <LoginForm onSuccess={(user) => dispatch({ screen: "main", user })} />}
{state.screen === "list" && <PostList kind={state.list} readIds={state.readIds} onSelect={submitFromClick} />}
{state.screen === "post" && state.postId !== null && <PostDetail postId={state.postId} />}
{state.error && <div className={`${styles.sub} ${styles.error}`}>{state.error}</div>}
+59
View File
@@ -0,0 +1,59 @@
import { useState, type FormEvent } from "react";
import styles from "./bbs.module.css";
// 개발은 로컬 백엔드 직접 호출, 운영(nginx)은 같은 도메인의 /api 프록시. NEXT_PUBLIC_API_URL로 덮어쓰기 가능
const API_URL =
process.env.NEXT_PUBLIC_API_URL ?? (process.env.NODE_ENV === "development" ? "http://localhost:8080" : "");
export default function LoginForm({ onSuccess }: { onSuccess: (user: string) => void }) {
const [error, setError] = useState<string | null>(null);
const [busy, setBusy] = useState(false);
const submit = async (e: FormEvent<HTMLFormElement>) => {
e.preventDefault();
const form = new FormData(e.currentTarget);
const username = String(form.get("username"));
setBusy(true);
setError(null);
try {
const res = await fetch(`${API_URL}/api/login`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ username, password: form.get("password") }),
});
if (!res.ok) throw new Error(res.status === 401 ? "아이디 또는 비밀번호가 틀렸습니다." : `서버 오류 (${res.status})`);
// ponytail: 토큰은 아직 쓰는 API가 없어 버림. 인증 API 호출이 생기면 저장해서 Authorization 헤더로 전달
onSuccess(username);
} catch (err) {
setError(err instanceof TypeError ? "서버에 연결할 수 없습니다." : (err as Error).message);
} finally {
setBusy(false);
}
};
return (
<>
<div className={styles.title}>[7] 로그인</div>
<div className={styles.sub}>아이디와 비밀번호를 입력하세요.</div>
<hr className={styles.rule} />
<form className={styles.loginForm} onSubmit={submit}>
<label>
<span className={styles.num}>ID</span>
<input name="username" autoComplete="username" required autoFocus />
</label>
<label>
<span className={styles.num}>PW</span>
<input name="password" type="password" autoComplete="current-password" required />
</label>
<button type="submit" disabled={busy}>
{busy ? "접속중..." : "로그인"}
</button>
</form>
{error && <div className={`${styles.sub} ${styles.error}`}>※ {error}</div>}
<hr className={styles.rule} />
<div className={styles.footer}>
<b>M</b>=메인메뉴
</div>
</>
);
}
+5 -3
View File
@@ -4,10 +4,11 @@ import styles from "./bbs.module.css";
interface Props {
readIds: number[];
loggedIn: boolean;
onSelect: (cmd: string) => void;
}
export default function MainMenu({ readIds, onSelect }: Props) {
export default function MainMenu({ readIds, loggedIn, onSelect }: Props) {
const unread = POSTS.length - readIds.length;
return (
@@ -18,8 +19,9 @@ export default function MainMenu({ readIds, onSelect }: Props) {
{MENU.map((m) => (
<div key={m.num} className={styles.row} onClick={() => onSelect(String(m.num))}>
<span className={styles.num}>{m.num}.</span>
<span>{m.label}</span>
<span className={styles.dim}>{m.en}</span>
<span>{m.key === "login" && loggedIn ? "로그아웃" : m.label}</span>
<span className={styles.dim}>{m.key === "login" && loggedIn ? "LOGOUT" : m.en}</span>
{m.key === "login" && <span className={styles.dim}>(L)</span>}
{m.key === "board" && <span className={styles.accent}>(안읽음 {unread})</span>}
{m.key === "viewed" && <span className={styles.accent}>({readIds.length}건)</span>}
</div>
@@ -61,6 +61,19 @@
.body { white-space: pre-wrap; margin-bottom: 14px; }
.loginForm { display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; }
.loginForm label { display: flex; gap: 10px; align-items: center; }
.loginForm input {
flex: 1; max-width: 260px; background: none; border: none; border-bottom: 1px solid var(--bbs-dim);
color: var(--bbs-fg); font: inherit; outline: none; caret-color: var(--bbs-highlight);
}
.loginForm input:focus { border-bottom-color: var(--bbs-accent); }
.loginForm button {
align-self: flex-start; background: none; border: 1px solid var(--bbs-accent); color: var(--bbs-accent);
font: inherit; padding: 0 12px; cursor: pointer;
}
.loginForm button:disabled { opacity: 0.5; cursor: wait; }
.footer { color: var(--bbs-dim); font-size: 11.5px; }
.footer b { color: var(--bbs-highlight); }
+1 -1
View File
@@ -7,7 +7,7 @@ export const MENU: MenuItem[] = [
{ num: 4, key: "youtube", label: "유튜브 자료실", en: "YOUTUBE", aliases: ["유튜브", "youtube"] },
{ num: 5, key: "about", label: "회사 소개", en: "ABOUT", aliases: ["소개", "회사소개", "about"] },
{ num: 6, key: "contact", label: "문의하기", en: "CONTACT", aliases: ["문의", "contact"] },
{ num: 7, key: "login", label: "로그아웃", en: "LOGOUT", aliases: ["로그인", "로그아웃", "login", "logout"] },
{ num: 7, key: "login", label: "로그인", en: "LOGIN", aliases: ["l", "로그인", "로그아웃", "login", "logout"] },
];
export const PALETTE_KEY = "bbs-palette";
+6 -4
View File
@@ -7,7 +7,7 @@ export const initialState: BbsState = {
list: "board",
postId: null,
readIds: [],
loggedIn: true,
user: null,
error: null,
};
@@ -19,8 +19,8 @@ function findMenu(raw: string): MenuItem | undefined {
}
/** 클릭/키보드 입력이 모두 거치는 단일 명령 처리기 (순수 함수 → useReducer reducer로 사용) */
export function execute(prev: BbsState, input: string | Nav): BbsState {
if (typeof input !== "string") return { ...prev, ...input, error: null }; // 뒤로/앞으로 이동 복원
export function execute(prev: BbsState, input: string | Nav | Partial<BbsState>): BbsState {
if (typeof input !== "string") return { ...prev, ...input, error: null }; // 뒤로/앞으로 이동 복원, 로그인 성공
const raw = input.trim();
if (!raw) return prev;
const state = { ...prev, error: null };
@@ -32,12 +32,14 @@ export function execute(prev: BbsState, input: string | Nav): BbsState {
const m = findMenu(raw);
if (!m) return { ...state, error: `※ 알 수 없는 메뉴입니다: "${raw}"` };
if (m.key === "board" || m.key === "viewed") return { ...state, screen: "list", list: m.key };
if (m.key === "login") return { ...state, loggedIn: !state.loggedIn };
if (m.key === "login") return state.user ? { ...state, user: null } : { ...state, screen: "login" };
return { ...state, error: `※ "${m.label}"는 이 목업에서는 미리보기 대상이 아닙니다 (BOARD/VIEWED만 시연).` };
}
if (isMain) return { ...state, screen: "main" };
if (state.screen === "login") return { ...state, error: '※ 위 칸에 아이디/비밀번호를 입력하거나 "M"(메인)을 입력하세요.' };
if (state.screen === "list") {
if (isList) return state;
const post = POSTS.find((p) => p.id === Number(raw));
+2 -2
View File
@@ -18,7 +18,7 @@ export interface Post {
}
export type Palette = "blue" | "green" | "amber";
export type Screen = "main" | "list" | "post";
export type Screen = "main" | "list" | "post" | "login";
export type ListKind = "board" | "viewed";
export interface BbsState {
@@ -26,7 +26,7 @@ export interface BbsState {
list: ListKind;
postId: number | null;
readIds: number[];
loggedIn: boolean;
user: string | null; // 로그인한 아이디, 비로그인이면 null
error: string | null;
}