Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

강원대 BE_오승환 2주차 과제(3단계) #449

Open
wants to merge 12 commits into
base: humpose
Choose a base branch
from
Prev Previous commit
Next Next commit
Feat: 스토리지에 토큰 추가
humpose committed Jul 6, 2024
commit ce4f2a83f4d1fefb661879877ddb9ea693900754
6 changes: 0 additions & 6 deletions src/main/java/gift/model/ProductDTO.java
Original file line number Diff line number Diff line change
@@ -44,15 +44,9 @@ public int getPrice() {
return price;
}

public void setPrice(int price) {
this.price = price;
}

public String getImageUrl() {
return imageUrl;
}

public void setImageUrl(String imageUrl) {
this.imageUrl = imageUrl; // image_url 사용
}
}
1 change: 0 additions & 1 deletion src/main/resources/templates/Login.html
Original file line number Diff line number Diff line change
@@ -2,7 +2,6 @@
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>로그인</title>

</head>
<body>
<h1>로그인</h1>
43 changes: 8 additions & 35 deletions src/main/resources/templates/Token.html
Original file line number Diff line number Diff line change
@@ -4,46 +4,19 @@
<title>로그인 성공</title>
<script>
document.addEventListener('DOMContentLoaded', function() {
const token = localStorage.getItem('jwtToken');
if (!token) {
alert('로그인이 필요합니다.');
window.location.href = '/users/login';
const token = /*[[${token}]]*/ 'DEFAULT_TOKEN';
if (token && token !== 'DEFAULT_TOKEN') {
localStorage.setItem('jwtToken', token);
alert('토큰이 저장되었습니다.');
window.location.href = '/wishlist';
} else {
fetch('/wishlist', {
method: 'GET',
headers: {
'Authorization': 'Bearer ' + token,
'Content-Type': 'application/json'
}
})
.then(response => {
if (response.status === 401) {
alert('인증 실패: 토큰이 유효하지 않거나 만료되었습니다.');
window.location.href = '/users/login';
} else {
return response.text();
}
})
.then(html => {
document.body.innerHTML = html;
})
.catch(error => console.error('Error:', error));
alert('토큰을 저장하는 데 실패했습니다.');
window.location.href = '/users/login';
}
});
</script>
</head>
<body>

<script>
document.addEventListener('DOMContentLoaded', function() {
const token = document.getElementById('token-text').innerText;
if (token && token !== 'DEFAULT_TOKEN') {
localStorage.setItem('jwtToken', token);
alert('토큰이 저장되었습니다.');
} else {
alert('토큰을 저장하는 데 실패했습니다.');
}
});
</script>
<div id="token-text" style="display: none;">[[${token}]]</div>
</body>
</html>