Fix: Transactions showing incorrect user data
The transactions were showing data from the wrong user. The `getTransacoes` function in `src/services/transacaoFetchService.ts` was updated to filter transactions by the logged-in user's email, matching the `login` column in the `transacoes` table.
This commit is contained in:
parent
9cd928329b
commit
10d79f0f4e
@ -28,6 +28,14 @@ const ProtectedRoute = ({ children }: ProtectedRouteProps) => {
|
||||
setSession(session);
|
||||
setLoggedIn(!!session);
|
||||
setUser(session?.user ? { id: session.user.id } : null);
|
||||
|
||||
// Store or remove user email from localStorage
|
||||
if (session?.user?.email) {
|
||||
localStorage.setItem('userEmail', session.user.email);
|
||||
} else {
|
||||
localStorage.removeItem('userEmail');
|
||||
}
|
||||
|
||||
setIsLoading(false);
|
||||
}
|
||||
);
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
|
||||
import { useState, useEffect, useCallback } from 'react';
|
||||
import { useState, useEffect } from 'react';
|
||||
import Layout from '@/components/layout/Layout';
|
||||
import SummaryCard from '@/components/dashboard/SummaryCard';
|
||||
import TransactionsTable from '@/components/dashboard/TransactionsTable';
|
||||
@ -33,24 +32,6 @@ const Dashboard = () => {
|
||||
|
||||
const [selectedMonth, setSelectedMonth] = useState<string>(getCurrentMonth());
|
||||
|
||||
// Use useCallback to ensure this function doesn't change on every render
|
||||
const setupUserId = useCallback(() => {
|
||||
const storedUserId = localStorage.getItem('userId');
|
||||
const finDashUser = localStorage.getItem('finDashUser');
|
||||
|
||||
if (!storedUserId && finDashUser) {
|
||||
localStorage.setItem('userId', finDashUser);
|
||||
} else if (!storedUserId && !finDashUser) {
|
||||
const defaultId = '9f267008-9128-4a2f-b730-de0a0b5602a9';
|
||||
localStorage.setItem('userId', defaultId);
|
||||
}
|
||||
}, []);
|
||||
|
||||
// Run the userId setup only once
|
||||
useEffect(() => {
|
||||
setupUserId();
|
||||
}, [setupUserId]);
|
||||
|
||||
// Load data when component mounts or month changes
|
||||
useEffect(() => {
|
||||
async function loadData() {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user