Skip to content

Commit

Permalink
Merge pull request #11 from Achintha444/fix-loading-glitch
Browse files Browse the repository at this point in the history
Fixed the loading glitch
  • Loading branch information
Achintha444 authored Dec 29, 2024
2 parents c1e2306 + 35ec7df commit c027027
Showing 1 changed file with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useAuthContext } from "@asgardeo/auth-react";
import { FunctionComponent, PropsWithChildren, ReactElement, useEffect, useState } from "react";
import { FunctionComponent, PropsWithChildren, ReactElement, useCallback, useEffect, useState } from "react";
import { useNavigate } from "react-router";
import InternalAuthDataContext from "../contexts/internalAuthDataContext";

Expand Down Expand Up @@ -31,6 +31,7 @@ const InternalAuthDataProvider: FunctionComponent<InternalAuthDataProviderProps>
useEffect(() => {
const loadUserData = async () => {
try {
setIsAuthenticationLoading(true);
const authenticated = await isAuthenticated();

if (authenticated) {
Expand All @@ -57,14 +58,14 @@ const InternalAuthDataProvider: FunctionComponent<InternalAuthDataProviderProps>
};

loadUserData();
}, [ isAuthenticated ]); //
}, []); //

/**
* Navigates to the provided route if the user is authenticated.
*
* @param route - Route to navigate to.
*/
const navigateToRouteOnAuthentication = (route: string): void => {
const navigateToRouteOnAuthentication = useCallback((route: string): void => {
setIsAuthenticationLoading(true);

isAuthenticated().then((response) => {
Expand All @@ -74,7 +75,7 @@ const InternalAuthDataProvider: FunctionComponent<InternalAuthDataProviderProps>
}).finally(() => {
setIsAuthenticationLoading(false);
});
};
}, [ isAuthenticated, navigate ]);

return (
<InternalAuthDataContext.Provider
Expand Down

0 comments on commit c027027

Please sign in to comment.