fix: sửa lỗi iphone ko thể upload

This commit is contained in:
2026-06-19 22:49:51 +07:00
parent 6c1b77d7d2
commit 36e8658dad
9 changed files with 160 additions and 24 deletions
+32 -1
View File
@@ -130,7 +130,7 @@ export const PublicPhotoModal: React.FC<PublicPhotoModalProps> = ({
}
}
const res = await fetch(`/api/v1/public-photos/${photo.id}/comments`, {
let res = await fetch(`/api/v1/public-photos/${photo.id}/comments`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
@@ -138,6 +138,37 @@ export const PublicPhotoModal: React.FC<PublicPhotoModalProps> = ({
},
body: JSON.stringify({ content: newComment })
});
if (res.status === 401) {
console.warn('Token invalid or expired. Creating a new guest user and retrying comment...');
localStorage.removeItem('guest_token');
localStorage.removeItem('guest_user');
localStorage.removeItem('token');
localStorage.removeItem('user');
const guestRes = await fetch('/api/v1/auth/create-guest', { method: 'POST' });
if (!guestRes.ok) throw new Error('Không thể tạo lại phiên khách.');
const guestData = await guestRes.json();
token = guestData.access_token;
currentUser = guestData.user;
localStorage.setItem('guest_token', token!);
localStorage.setItem('guest_user', JSON.stringify(currentUser));
localStorage.setItem('token', token!);
localStorage.setItem('user', JSON.stringify(currentUser));
if (onLoginSuccess) {
onLoginSuccess(currentUser);
}
res = await fetch(`/api/v1/public-photos/${photo.id}/comments`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${token}`
},
body: JSON.stringify({ content: newComment })
});
}
if (res.ok) {
setNewComment('');