fix: guest and admin logic
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user