Skip to content

Commit e7562ed

Browse files
fix: solucionando problema de redireccion de ruta cuando reargaba
1 parent 2a8ae02 commit e7562ed

2 files changed

Lines changed: 7 additions & 2 deletions

File tree

client/src/app/App.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@ import useAvoidZoom from '@/shared/hooks/useAvoidZoom';
1111
import { Layout } from '@/app/layouts/Layout';
1212

1313
const App = () => {
14-
const { user } = UserAuth();
14+
const { user, loading } = UserAuth();
1515
const location = useLocation();
1616
const isAuthenticated = !isEmptyObject(user);
1717

1818
useAvoidZoom();
1919

20+
if (loading) return null;
21+
2022
return (
2123
<Routes>
2224
<Route

client/src/app/context/AuthContext.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@ const AuthContext = createContext({
1212
fullname: '',
1313
picture: '',
1414
} as UserProps,
15+
loading: true,
1516
});
1617

1718
export const AuthContextProvider = ({ children }: { children: ReactNode }) => {
1819
const navigate = useNavigate();
1920
const [user, setUser] = useState({} as UserProps);
21+
const [loading, setLoading] = useState(true);
2022

2123
async function signInWithGoogle() {
2224
try {
@@ -67,14 +69,15 @@ export const AuthContextProvider = ({ children }: { children: ReactNode }) => {
6769
picture: session.user.user_metadata.picture,
6870
});
6971
}
72+
setLoading(false);
7073
});
7174
return () => {
7275
authListener.subscription.unsubscribe();
7376
};
7477
}, [navigate]);
7578

7679
return (
77-
<AuthContext.Provider value={{ signInWithGoogle, signInWithGithub, signout, user }}>
80+
<AuthContext.Provider value={{ signInWithGoogle, signInWithGithub, signout, user, loading }}>
7881
{children}
7982
</AuthContext.Provider>
8083
);

0 commit comments

Comments
 (0)