Skip to content

Commit ef6153d

Browse files
committed
로그인 필요 시 안내 및 UI 중앙 배치
1 parent 10be0d0 commit ef6153d

3 files changed

Lines changed: 23 additions & 27 deletions

File tree

src/components/codecast/Codecast.css

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,15 @@
33
.broadcast-container {
44
background-color: #ffffff;
55
min-height: 100vh;
6-
padding: 100px 20px;
6+
display: flex; /* 가운데 정렬용 */
7+
justify-content: center; /* 가로 가운데 */
8+
align-items: center; /* 세로 가운데 */
9+
flex-direction: column; /* 위아래 배치 */
10+
padding: 20px; /* 좌우만 여백 */
711
text-align: center;
812
}
913

14+
1015
.broadcast-header {
1116
margin-bottom: 30px;
1217
}

src/components/community/Community.jsx

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { useEffect, useState } from "react";
2-
import {useNavigate} from "react-router-dom";
2+
import { useNavigate } from "react-router-dom";
33
import "./Community.css";
44

55
const API_BASE = "http://52.79.145.160:8080";
@@ -24,19 +24,18 @@ export default function Community() {
2424
setError("");
2525

2626
const token = localStorage.getItem("token");
27-
if (!token) {
28-
// 🚨 비회원 접근 차단
29-
alert("로그인이 필요합니다.");
30-
navigate("/");
31-
return;
27+
28+
// ✅ 토큰이 있으면 Authorization 헤더 추가
29+
const headers = {
30+
Accept: "application/json",
31+
};
32+
if (token) {
33+
headers.Authorization = `Bearer ${token}`;
3234
}
3335

3436
const res = await fetch(`${API_BASE}/api/posts`, {
3537
method: "GET",
36-
headers: {
37-
Accept: "application/json",
38-
Authorization: `Bearer ${token}`,
39-
},
38+
headers,
4039
signal: controller.signal,
4140
credentials: "include",
4241
});
@@ -56,7 +55,6 @@ export default function Community() {
5655
.sort((a, b) => {
5756
const diff = getTime(b.createdAt) - getTime(a.createdAt);
5857
if (diff !== 0) return diff;
59-
// createdAt이 같거나 비어있으면 id 내림차순으로 보정
6058
return (b.id ?? 0) - (a.id ?? 0);
6159
});
6260

@@ -155,12 +153,11 @@ export default function Community() {
155153
<div
156154
key={post.id}
157155
className="post-card"
158-
onClick={() => navigate(`/community/post/${post.id}`)} // ← id 사용
156+
onClick={() => navigate(`/community/post/${post.id}`)}
159157
style={{ cursor: "pointer" }}
160158
>
161159
<div className="post-meta">
162160
<div className="title-row">
163-
{/* 상태값 없으면 뱃지 숨김 */}
164161
{post.status ? (
165162
<span className={`badge ${post.status === "해결됨" ? "badge-solved" : ""}`}>
166163
{post.status}
@@ -190,7 +187,6 @@ export default function Community() {
190187
</div>
191188
)}
192189

193-
{/* 기존 페이징 UI는 유지 (서버 페이징 스펙 나오면 연결) */}
194190
<div className="pagination-wrapper">
195191
<div className="page-numbers">
196192
<button className="page-button active">1</button>

src/components/community/CommunityWrite.jsx

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const ALLOWED_TAGS = [
1313
"JAVA","C","CPP","JPA","JAVASCRIPT","PYTHON","OOP","BIGDATA","SPRING","TYPESCRIPT","ML"
1414
];
1515

16-
// ✅ 흔한 표기 → ENUM 매핑(한국어/소문자/동의어 흡수)
16+
// ✅ 흔한 표기 → ENUM 매핑
1717
const TAG_SYNONYM = {
1818
js: "JAVASCRIPT", javascript: "JAVASCRIPT", 자바스크립트: "JAVASCRIPT",
1919
java: "JAVA", 자바: "JAVA",
@@ -31,15 +31,15 @@ function normalizeToEnumTag(raw) {
3131
if (!raw) return null;
3232
const k = raw.replace(/^#/, "").trim();
3333
const keyLC = k.toLowerCase();
34-
if (TAG_SYNONYM[keyLC]) return TAG_SYNONYM[keyLC]; // 동의어 우선
34+
if (TAG_SYNONYM[keyLC]) return TAG_SYNONYM[keyLC];
3535
const upper = k.toUpperCase();
3636
return ALLOWED_TAGS.includes(upper) ? upper : null;
3737
}
3838

3939
// 입력 문자열 → ENUM 배열(중복 제거, 최대 10개)
4040
function parseTagsInput(input) {
4141
const list = input
42-
.split(/[#,,\s]+/) // 쉼표/공백/# 구분
42+
.split(/[#,,\s]+/)
4343
.map(normalizeToEnumTag)
4444
.filter(Boolean);
4545
return Array.from(new Set(list)).slice(0, 10);
@@ -59,11 +59,12 @@ export default function CommunityWrite() {
5959
const [content, setContent] = useState(defaultGuide);
6060
const [submitting, setSubmitting] = useState(false);
6161

62-
// 비회원 접근 차단(알림은 로그인 페이지에서 처리)
62+
// 비회원 접근 차단: 알림 + 커뮤니티 페이지로 이동
6363
useEffect(() => {
6464
const token = localStorage.getItem("token");
6565
if (!token) {
66-
navigate("/", { replace: true, state: { reason: "auth-required", from: location.pathname } });
66+
alert("로그인이 필요합니다.");
67+
navigate("/community", { replace: true, state: { from: location.pathname } });
6768
}
6869
}, [navigate, location.pathname]);
6970

@@ -77,7 +78,7 @@ export default function CommunityWrite() {
7778
const handleSubmit = async () => {
7879
const token = localStorage.getItem("token");
7980
if (!token) {
80-
navigate("/login", { replace: true, state: { reason: "auth-required", from: location.pathname } });
81+
// 🚨 여기서는 다시 알림 필요 없음 → 이미 진입 차단됨
8182
return;
8283
}
8384

@@ -88,10 +89,8 @@ export default function CommunityWrite() {
8889
return;
8990
}
9091

91-
// ✅ 태그 정규화/검증 → ENUM 배열
9292
const tagArray = parseTagsInput(tags);
9393

94-
// 사용자가 뭔가 입력했는데 결과가 0개면 허용값 아님
9594
if (tags.trim() && tagArray.length === 0) {
9695
alert(`지원하는 태그만 사용할 수 있어요.\n허용값: ${ALLOWED_TAGS.join(", ")}`);
9796
return;
@@ -114,10 +113,6 @@ export default function CommunityWrite() {
114113
body: JSON.stringify(payload),
115114
});
116115

117-
if (res.status === 401 || res.status === 403) {
118-
navigate("/login", { replace: true, state: { reason: "auth-required", from: location.pathname } });
119-
return;
120-
}
121116
if (!res.ok) {
122117
const ct = res.headers.get("content-type") || "";
123118
const msg = ct.includes("application/json") ? (await res.json()).message : await res.text();

0 commit comments

Comments
 (0)