Fix post-login: re-read user role on every route change
All checks were successful
Build frontend / build (push) Successful in 55s

- ClientLayout: separated user loading into useEffect with pathname dependency
- Homepage: same fix - re-read user from JWT on route change
- Fixes issue where navbar/dashboard links didn't appear until page reload
This commit is contained in:
Claw AI
2026-03-29 12:22:16 +00:00
parent 16038a80dd
commit 253bb875ab
2 changed files with 21 additions and 11 deletions

View File

@ -2,6 +2,7 @@
import { useState, useRef, useEffect } from 'react';
import { motion, AnimatePresence } from 'framer-motion';
import { usePathname } from 'next/navigation';
import {
ShieldCheck,
Lock,
@ -96,11 +97,12 @@ export default function HomePage() {
const [user, setUser] = useState(null);
const [showUserMenu, setShowUserMenu] = useState(false);
const menuRef = useRef(null);
const pathname = usePathname();
const [allProperties, setAllProperties] = useState([]);
const [loading, setLoading] = useState(true);
// Fetch properties from API on mount
// Re-read user from JWT on every route change
useEffect(() => {
const authUser = AuthService.getUser();
if (authUser) {
@ -109,7 +111,13 @@ export default function HomePage() {
email: authUser.email,
role: AuthService.isOwner() ? 'owner' : 'customer',
});
} else {
setUser(null);
}
}, [pathname]);
// Fetch properties from API on mount
useEffect(() => {
async function fetchProperties() {
try {