fix: Login flow - remove reload, sync auth state reactively

This commit is contained in:
dwindown
2025-11-04 23:19:53 +07:00
parent 4e1eb22c8f
commit e8e380231e
4 changed files with 12 additions and 7 deletions

View File

@@ -405,6 +405,13 @@ function AuthWrapper() {
const location = useLocation();
useEffect(() => {
// Check if config was updated (e.g., after login)
if (window.WNW_CONFIG?.isAuthenticated !== isAuthenticated) {
setIsAuthenticated(window.WNW_CONFIG.isAuthenticated);
setIsChecking(false);
return;
}
if (window.WNW_CONFIG?.standaloneMode) {
fetch(window.WNW_CONFIG.restUrl + '/auth/check', {
credentials: 'include',
@@ -414,12 +421,13 @@ function AuthWrapper() {
setIsAuthenticated(data.authenticated);
if (data.authenticated && data.user) {
window.WNW_CONFIG.currentUser = data.user;
window.WNW_CONFIG.isAuthenticated = true;
}
})
.catch(() => setIsAuthenticated(false))
.finally(() => setIsChecking(false));
}
}, []);
}, [location.pathname, isAuthenticated]);
if (isChecking) {
return (