Skip to content

Commit a3b1e1c

Browse files
committed
Merge remote-tracking branch 'origin/sunwoong'
2 parents 9c41425 + d2e1efc commit a3b1e1c

File tree

4 files changed

+49
-17
lines changed

4 files changed

+49
-17
lines changed

src/App.js

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,8 @@ import ScrollToTop from "./components/common/ScrollToTop";
1919

2020
function App() {
2121
const [isDark, setIsDark] = useState(false);
22-
23-
useEffect(() => {
24-
document.body.classList.toggle("dark-mode", isDark);
25-
}, [isDark]);
22+
const [isLoggedIn, setIsLoggedIn] = useState(false);
23+
const [nickname, setNickname] = useState('');
2624

2725
useEffect(() => {
2826
const savedTheme = localStorage.getItem("theme");
@@ -36,9 +34,22 @@ function App() {
3634
localStorage.setItem("theme", isDark ? "dark" : "light");
3735
}, [isDark]);
3836

37+
useEffect(() => {
38+
const token = localStorage.getItem("token");
39+
const name = localStorage.getItem("username"); // ✅ 이름을 불러옴
40+
41+
if (token && name) {
42+
setIsLoggedIn(true);
43+
setNickname(name); // ✅ 이름을 nickname으로 사용
44+
} else {
45+
setIsLoggedIn(false);
46+
setNickname('');
47+
}
48+
}, []);
49+
3950
return (
4051
<HashRouter>
41-
<Header isDark={isDark} setIsDark={setIsDark} />
52+
<Header isDark={isDark} setIsDark={setIsDark} isLoggedIn={isLoggedIn} nickname={nickname} />
4253
<ScrollToTop />
4354
<Routes>
4455
<Route path="/" element={<Main />} />
@@ -61,4 +72,4 @@ function App() {
6172
);
6273
}
6374

64-
export default App;
75+
export default App;

src/components/header/Header.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@
9494

9595
/* 로그인 상태일 때 닉네임 표시 */
9696
.user-nickname {
97-
font-size: 14px;
97+
font-size: 17px;
9898
font-weight: 600;
9999
color: #6a0dad;
100100
padding: 6px 12px;

src/components/header/Header.jsx

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1-
import React, { useState, useEffect } from "react";
1+
import React from "react";
22
import { NavLink, Link } from "react-router-dom";
3+
import { Link as ScrollLink } from "react-scroll";
34
import { FaMoon, FaSun } from "react-icons/fa";
45
import "./Header.css";
56

6-
const Header = ({ isLoggedIn, nickname, isDark, setIsDark }) => {
7-
useEffect(() => {
8-
document.body.classList.toggle("dark-mode", isDark);
9-
}, [isDark]);
7+
const Header = ({ isDark, setIsDark, isLoggedIn, nickname }) => {
8+
const handleLogout = () => {
9+
localStorage.clear();
10+
window.location.reload(); // 새로고침으로 상태 초기화
11+
};
1012

1113
return (
1214
<header className="custom-header">
@@ -16,6 +18,14 @@ const Header = ({ isLoggedIn, nickname, isDark, setIsDark }) => {
1618

1719
<nav className="header-nav">
1820
<NavLink to="/" end></NavLink>
21+
<ScrollLink
22+
to="feature"
23+
smooth
24+
duration={500}
25+
offset={-64}
26+
spy={true}
27+
activeClass="active"
28+
></ScrollLink>
1929
<NavLink to="/ide">IDE</NavLink>
2030
<NavLink to="/community">커뮤니티</NavLink>
2131
<NavLink to="/broadcast">코드 방송</NavLink>
@@ -27,10 +37,14 @@ const Header = ({ isLoggedIn, nickname, isDark, setIsDark }) => {
2737
className="theme-toggle-btn"
2838
aria-label="Toggle theme"
2939
>
30-
{isDark ? <FaSun/> : <FaMoon/>}
40+
{isDark ? <FaSun /> : <FaMoon />}
3141
</button>
42+
3243
{isLoggedIn ? (
33-
<span className="user-nickname">👤 {nickname}</span>
44+
<>
45+
<span className="user-nickname">👤 {nickname}</span>
46+
<button onClick={handleLogout} className="btn btn-outline">로그아웃</button>
47+
</>
3448
) : (
3549
<>
3650
<Link to="/login" className="btn btn-outline">로그인</Link>

src/components/login/Login.jsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@ import React, { useState } from 'react';
22
import axios from 'axios';
33
import config from '../../config';
44
import './Login.css';
5+
import { useNavigate } from 'react-router-dom';
56

67
function Login() {
78
const [formData, setFormData] = useState({
89
username: '',
910
password: '',
1011
});
1112

13+
const navigate = useNavigate();
14+
1215
const handleChange = (e) => {
1316
setFormData({
1417
...formData,
@@ -29,13 +32,15 @@ function Login() {
2932

3033
console.log('✅ 로그인 성공:', response.data);
3134

35+
// 사용자 정보 저장
3236
localStorage.setItem('token', token);
33-
localStorage.setItem('username', name);
37+
localStorage.setItem('username', name); // ✅ 이름 저장
3438
localStorage.setItem('userId', userId);
3539
localStorage.setItem('role', role);
3640

37-
alert('로그인 성공!');
38-
// window.location.href = '/'; // 필요한 경우 이동
41+
// 메인 페이지 이동 및 상태 반영 위해 새로고침
42+
navigate('/', { replace: true });
43+
window.location.reload();
3944
} catch (error) {
4045
console.error('❌ 로그인 실패:', error.response?.data || error.message);
4146
alert(error.response?.data?.message || '로그인에 실패했습니다.');
@@ -58,6 +63,7 @@ function Login() {
5863
onChange={handleChange}
5964
required
6065
/>
66+
6167
<div className="password-container">
6268
<label htmlFor="password">비밀번호</label>
6369
<a href="/forgot-password">비밀번호 찾기</a>
@@ -84,6 +90,7 @@ function Login() {
8490
<button disabled>Google</button>
8591
<button disabled>Github</button>
8692
</div>
93+
8794
<p className="signup-link">
8895
계정이 없으신가요? <a href="/signup">회원가입</a>
8996
</p>

0 commit comments

Comments
 (0)