Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
F
Festivelo_frontend
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Festivelo
Festivelo_frontend
Commits
55e48d57
Commit
55e48d57
authored
5 months ago
by
nahyun
Browse files
Options
Downloads
Patches
Plain Diff
refector: 코드 정리
parent
dfca91aa
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/App.js
+2
-90
2 additions, 90 deletions
src/App.js
src/pages/Login.js
+3
-21
3 additions, 21 deletions
src/pages/Login.js
with
5 additions
and
111 deletions
src/App.js
+
2
−
90
View file @
55e48d57
...
...
@@ -34,14 +34,8 @@ export function useToast() {
// // setIsAuthenticated(false);
// // };
// //jwt 전 로그인-------------------------
// //jwt 후 로그인-------------------------
// const logout = () => {
// localStorage.removeItem('token');
// delete axios.defaults.headers.common['Authorization'];
// setUser(null);
// setIsAuthenticated(false);
// };
//jwt 후 로그인-------------------------
function
App
()
{
const
[
isAuthenticated
,
setIsAuthenticated
]
=
useState
(()
=>
{
...
...
@@ -69,35 +63,6 @@ function App() {
setLastActivity
(
Date
.
now
());
};
// // 토큰 만료 체크 함수
// const checkTokenExpiration = () => {
// const token = localStorage.getItem('token');
// if (token) {
// try {
// const decoded = jwt_decode(token);
// if (decoded.exp * 1000 < Date.now()) {
// // 토큰 만료시 로그아웃과 동일한 효과
// localStorage.removeItem('token');
// setUser(null);
// setIsAuthenticated(false);
// toast.info('세션이 만료되었습니다. 다시 로그인해주세요.');
// }
// } catch (error) {
// localStorage.removeItem('token');
// setUser(null);
// setIsAuthenticated(false);
// }
// }
// };
// // 주기적으로 토큰 체크 (30초마다)
// React.useEffect(() => {
// const timer = setInterval(checkTokenExpiration, 30000);
// // 컴포넌트가 언마운트될 때 타이머 정리
// return () => clearInterval(timer);
// }, []);
// 추가--------------------------------
// 토큰 갱신 함수
const
refreshToken
=
async
()
=>
{
try
{
...
...
@@ -134,53 +99,6 @@ function App() {
}
};
// 사용자 활동 감지 - 안되면 다시 활성화
// useEffect(() => {
// const updateActivity = async (e) => {
// // input 태그나 textarea에서의 이벤트는 무시
// if (e.target.tagName.toLowerCase() === 'input' ||
// e.target.tagName.toLowerCase() === 'textarea') {
// console.log('입력 필드 이벤트 무시');
// return;
// }
// const now = Date.now();
// const timeSinceLastRefresh = now - lastTokenRefresh;
// setLastActivity(now);
// console.log('활동 감지:', {
// 현재시간: new Date(now).toLocaleString(),
// 마지막갱신: new Date(lastTokenRefresh).toLocaleString(),
// 경과시간: Math.floor(timeSinceLastRefresh / 1000 / 60) + '분'
// });
// // 마지막 토큰 갱신으로부터 00분 이상 지났을 때만 갱신
// if (timeSinceLastRefresh > (process.env.REACT_APP_TOKEN_EXPIRATION-1) * 60 * 1000) {
// console.log('토큰 갱신 시도...');
// await refreshToken();
// } else {
// console.log(`토큰 갱신까지 ${Math.ceil((process.env.REACT_APP_TOKEN_EXPIRATION-1) - timeSinceLastRefresh/1000/60)}분 남음`);
// }
// };
// console.log('이벤트 리스너 등록됨');
// window.addEventListener('mousemove', updateActivity);
// window.addEventListener('keydown', updateActivity);
// window.addEventListener('click', updateActivity);
// window.addEventListener('scroll', updateActivity);
// window.addEventListener('touchstart', updateActivity);
// return () => {
// console.log('이벤트 리스너 제거됨');
// window.removeEventListener('mousemove', updateActivity);
// window.removeEventListener('keydown', updateActivity);
// window.removeEventListener('click', updateActivity);
// window.removeEventListener('scroll', updateActivity);
// window.removeEventListener('touchstart', updateActivity);
// };
// }, [lastTokenRefresh]);
//안되면 다시 활성화 -------------
const
logout
=
()
=>
{
localStorage
.
removeItem
(
'
token
'
);
setUser
(
null
);
...
...
@@ -228,7 +146,7 @@ useEffect(() => {
useEffect
(()
=>
{
const
checkInactivity
=
()
=>
{
const
inactiveTime
=
Date
.
now
()
-
lastActivity
;
if
(
inactiveTime
>
process
.
env
.
REACT_APP_TOKEN_EXPIRATION
*
60
*
1000
)
{
// 토큰 만료시간
if
(
inactiveTime
>
process
.
env
.
REACT_APP_TOKEN_EXPIRATION
*
60
*
1000
)
{
// 토큰 만료시간
: REACT_APP_TOKEN_EXPIRATION 확인
logout
();
toast
.
info
(
'
장시간 활동이 없어 로그아웃되었습니다.
'
);
}
...
...
@@ -237,7 +155,6 @@ useEffect(() => {
const
interval
=
setInterval
(
checkInactivity
,
30000
);
// 30초마다 체크
return
()
=>
clearInterval
(
interval
);
},
[
lastActivity
]);
//--------------------------------
const
login
=
(
userData
)
=>
{
setUser
(
userData
);
...
...
@@ -261,11 +178,6 @@ useEffect(() => {
);
}
// function PrivateRoute({ children }) {
// const { isAuthenticated } = useAuth();
// return isAuthenticated ? children : <Navigate to="/login" />;
// }
function
PrivateRoute
({
children
})
{
const
{
isAuthenticated
}
=
useAuth
();
const
token
=
localStorage
.
getItem
(
'
token
'
);
...
...
This diff is collapsed.
Click to expand it.
src/pages/Login.js
+
3
−
21
View file @
55e48d57
...
...
@@ -18,7 +18,7 @@ function Login() {
const
toast
=
useToast
();
//
jwt 전
로그인-------------------------
//
세션
로그인-------------------------
// useEffect(() => {
// const params = new URLSearchParams(window.location.search);
// const userParam = params.get('user');
...
...
@@ -35,7 +35,7 @@ function Login() {
// }
// }
// }, [navigate, login, toast]);
//jwt 전 로그인-------------------------
//jwt 후 로그인-------------------------
useEffect
(()
=>
{
const
params
=
new
URLSearchParams
(
window
.
location
.
hash
.
substring
(
1
));
...
...
@@ -59,10 +59,9 @@ function Login() {
navigate
(
'
/
'
);
}
},
[
navigate
,
login
,
toast
]);
//jwt 후 로그인-------------------------
//
jwt 전
로그인-------------------------
//
세션
로그인-------------------------
// const handleLogin = async (e) => {
// e.preventDefault();
// setLoading(true);
...
...
@@ -91,7 +90,6 @@ function Login() {
// setLoading(false);
// }
// };
//jwt 전 로그인-------------------------
//jwt 후 로그인-------------------------
// handleLogin 함수만 수정
...
...
@@ -100,22 +98,6 @@ const handleLogin = async (e) => {
setLoading
(
true
);
try
{
// const response = await axios.post('http://localhost:8000/login', {
// email: username,
// password: password
// });
// if (response.status === 200) {
// // JWT 토큰 저장
// const { token, user } = response.data;
// localStorage.setItem('token', token);
// // axios 기본 헤더에 토큰 설정
// axios.defaults.headers.common['Authorization'] = `Bearer ${token}`;
// login(user);
// toast.success('로그인에 성공했습니다.');
// navigate('/');
// }
const
response
=
await
axios
.
post
(
`
${
API_URL
}
/login`
,
{
email
:
username
,
password
:
password
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment