fix: consulting slots display and auth reload redirect
- Group consulting slots by date in admin order detail modal - Show time range from first slot start to last slot end - Display session count badge for multi-slot orders - Fix page reload redirecting to main page by ensuring loading state is properly synchronized with Supabase session initialization - Add mounted flag to prevent state updates after unmount 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -21,31 +21,46 @@ export function AuthProvider({ children }: { children: ReactNode }) {
|
||||
const [isAdmin, setIsAdmin] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
const { data: { subscription } } = supabase.auth.onAuthStateChange(
|
||||
(event, session) => {
|
||||
setSession(session);
|
||||
setUser(session?.user ?? null);
|
||||
|
||||
if (session?.user) {
|
||||
setTimeout(() => {
|
||||
checkAdminRole(session.user.id);
|
||||
}, 0);
|
||||
} else {
|
||||
setIsAdmin(false);
|
||||
}
|
||||
}
|
||||
);
|
||||
let mounted = true;
|
||||
|
||||
// First, get the initial session
|
||||
supabase.auth.getSession().then(({ data: { session } }) => {
|
||||
if (!mounted) return;
|
||||
|
||||
setSession(session);
|
||||
setUser(session?.user ?? null);
|
||||
|
||||
if (session?.user) {
|
||||
checkAdminRole(session.user.id);
|
||||
}
|
||||
|
||||
// Only set loading to false after initial session is loaded
|
||||
setLoading(false);
|
||||
});
|
||||
|
||||
return () => subscription.unsubscribe();
|
||||
// Then listen for auth state changes
|
||||
const { data: { subscription } } = supabase.auth.onAuthStateChange(
|
||||
(event, session) => {
|
||||
if (!mounted) return;
|
||||
|
||||
setSession(session);
|
||||
setUser(session?.user ?? null);
|
||||
|
||||
if (session?.user) {
|
||||
checkAdminRole(session.user.id);
|
||||
} else {
|
||||
setIsAdmin(false);
|
||||
}
|
||||
|
||||
// Ensure loading is false after auth state changes
|
||||
setLoading(false);
|
||||
}
|
||||
);
|
||||
|
||||
return () => {
|
||||
mounted = false;
|
||||
subscription.unsubscribe();
|
||||
};
|
||||
}, []);
|
||||
|
||||
const checkAdminRole = async (userId: string) => {
|
||||
|
||||
Reference in New Issue
Block a user