no more 401 error for publicly browsing user
This commit is contained in:
@@ -230,7 +230,7 @@ const AuthModal: React.FC<AuthModalProps> = ({
|
||||
disabled={loading}
|
||||
>
|
||||
<i className="bi bi-google me-2"></i>
|
||||
Sign in with Google
|
||||
Continue with Google
|
||||
</button>
|
||||
|
||||
<div className="text-center mt-3">
|
||||
|
||||
@@ -44,14 +44,16 @@ export const AuthProvider: React.FC<AuthProviderProps> = ({ children }) => {
|
||||
|
||||
const checkAuth = async () => {
|
||||
try {
|
||||
// The axios interceptor will automatically handle token refresh if needed
|
||||
const response = await userAPI.getProfile();
|
||||
setUser(response.data);
|
||||
// Use the status endpoint which returns 200 for both authenticated and unauthenticated states
|
||||
const response = await authAPI.getStatus();
|
||||
|
||||
if (response.data.authenticated) {
|
||||
setUser(response.data.user);
|
||||
} else {
|
||||
setUser(null);
|
||||
}
|
||||
} catch (error: any) {
|
||||
// If we get here, either:
|
||||
// 1. User is not logged in (expected for public browsing)
|
||||
// 2. Token refresh failed (user needs to login again)
|
||||
// In both cases, silently set user to null without logging errors
|
||||
// If we get here, there's a network or server error
|
||||
setUser(null);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -157,6 +157,7 @@ export const authAPI = {
|
||||
logout: () => api.post("/auth/logout"),
|
||||
refresh: () => api.post("/auth/refresh"),
|
||||
getCSRFToken: () => api.get("/auth/csrf-token"),
|
||||
getStatus: () => api.get("/auth/status"),
|
||||
};
|
||||
|
||||
export const userAPI = {
|
||||
@@ -280,23 +281,4 @@ export const conditionCheckAPI = {
|
||||
getAvailableChecks: () => api.get("/condition-checks"),
|
||||
};
|
||||
|
||||
export const notificationAPI = {
|
||||
getNotifications: (params?: { limit?: number; page?: number }) =>
|
||||
api.get("/notifications", { params }),
|
||||
getUnreadCount: () => api.get("/notifications/unread-count"),
|
||||
markAsRead: (notificationId: string) =>
|
||||
api.patch(`/notifications/${notificationId}/read`),
|
||||
markAllAsRead: () => api.patch("/notifications/mark-all-read"),
|
||||
// Development endpoints
|
||||
createTestNotification: (data: {
|
||||
type?: string;
|
||||
title: string;
|
||||
message: string;
|
||||
metadata?: any;
|
||||
}) => api.post("/notifications/test", data),
|
||||
triggerConditionReminders: () =>
|
||||
api.post("/notifications/test/condition-reminders"),
|
||||
cleanupExpired: () => api.post("/notifications/test/cleanup-expired"),
|
||||
};
|
||||
|
||||
export default api;
|
||||
|
||||
Reference in New Issue
Block a user