fix: JWT not persisting after reboot

This commit is contained in:
LukeGus
2025-10-31 17:48:18 -05:00
parent 6125ba4931
commit 5c7cc078ad
7 changed files with 177 additions and 113 deletions

View File

@@ -91,18 +91,6 @@ export function Auth({
setInternalLoggedIn(loggedIn);
}, [loggedIn]);
useEffect(() => {
const clearJWTOnLoad = async () => {
try {
await logoutUser();
} catch {
// Ignore logout errors on initial load
}
};
clearJWTOnLoad();
}, []);
useEffect(() => {
getRegistrationAllowed().then((res) => {
setRegistrationAllowed(res.allowed);

View File

@@ -34,13 +34,6 @@ function AppContent() {
setIsAuthenticated(true);
setIsAdmin(!!meRes.is_admin);
setUsername(meRes.username || null);
if (!meRes.data_unlocked) {
console.warn("User data is locked - re-authentication required");
setIsAuthenticated(false);
setIsAdmin(false);
setUsername(null);
}
})
.catch((err) => {
setIsAuthenticated(false);

View File

@@ -133,18 +133,6 @@ export function Auth({
setInternalLoggedIn(loggedIn);
}, [loggedIn]);
useEffect(() => {
const clearJWTOnLoad = async () => {
try {
await logoutUser();
} catch (error) {
console.log("JWT cleanup on HomepageAuth load:", error);
}
};
clearJWTOnLoad();
}, []);
useEffect(() => {
getRegistrationAllowed().then((res) => {
setRegistrationAllowed(res.allowed);

View File

@@ -31,13 +31,6 @@ const AppContent: FC = () => {
setIsAuthenticated(true);
setIsAdmin(!!meRes.is_admin);
setUsername(meRes.username || null);
if (!meRes.data_unlocked) {
console.warn("User data is locked - re-authentication required");
setIsAuthenticated(false);
setIsAdmin(false);
setUsername(null);
}
})
.catch((err) => {
setIsAuthenticated(false);

View File

@@ -310,6 +310,10 @@ function createApiInstance(
if (isSessionExpired && typeof window !== "undefined") {
console.warn("Session expired - please log in again");
// Clear the JWT cookie to prevent reload loop
document.cookie =
"jwt=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;";
import("sonner").then(({ toast }) => {
toast.warning("Session expired - please log in again");
});