fix: guest and admin logic

This commit is contained in:
2026-06-22 11:41:34 +07:00
parent b1a539235b
commit 860395cb14
61 changed files with 1291 additions and 244 deletions
+23 -8
View File
@@ -92,15 +92,30 @@ export const useTourStore = create<TourState>((set, get) => ({
const token = localStorage.getItem('token');
if (!token) return;
const response = await fetch(`/api/v1/tours/explore`, {
headers: {
'Authorization': `Bearer ${token}`
try {
const response = await fetch(`/api/v1/tours/explore`, {
headers: {
'Authorization': `Bearer ${token}`
}
});
// If response is 401 or 403, the user is likely anonymous and rejected by backend
if (response.status === 401 || response.status === 403) {
const errorData = await response.json();
throw new Error(errorData.message || 'Tài khoản khách không có quyền truy cập');
}
});
if (!response.ok) return;
const data = await response.json();
set({ publicTours: data });
if (!response.ok) {
throw new Error(`HTTP ${response.status}`);
}
const data = await response.json();
set({ publicTours: data });
} catch (error: any) {
console.error('[fetchPublicTours] Error:', error.message);
// Re-throw the error so MemberDashboard can catch it and redirect
throw error;
}
},
fetchPublicTourDetails: async (tourId: string) => {
try {