mirror of
https://github.com/headporter81/ss-front-react.git
synced 2026-12-06 07:41:11 +09:00
feat : BBS 7번 메뉴 로그인/로그아웃 및 로그인 화면 추가
SpecialSource Frontend (React) CD / deploy (push) Successful in 11s
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:
1 parent
d925a1599d
commit
2a09fa80a9
7 files changed
+92
-12
No files matched your search
@@ -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>}
|
||||
|
||||
@@ -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>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -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); }
|
||||
|
||||
|
||||
Reference in new issue
Block a user