1- import { Dispatch , FC , ReactNode , SetStateAction , useEffect , useState } from 'react'
1+ import { Dispatch , FC , ReactNode , SetStateAction , useEffect , useRef , useState } from 'react'
22
33import { userUpdatePasswordAsync } from '../../auth'
44import { ChangePasswordRequest } from '../change-password-request.model'
@@ -18,13 +18,21 @@ export const ProfileProvider: FC<ProfileProviderProps> = (props: ProfileProvider
1818 const [ profileContextData , setProfileContextData ] :
1919 [ ProfileContextData , Dispatch < SetStateAction < ProfileContextData > > ]
2020 = useState < ProfileContextData > ( defaultProfileContextData )
21+ const isFetchingProfileRef = useRef < boolean > ( false )
2122
2223 function changePassword ( userId : number , request : ChangePasswordRequest ) : Promise < void > {
2324 return userUpdatePasswordAsync ( userId , request . password , request . newPassword )
2425 }
2526
2627 async function getAndSetProfileAsync ( ) : Promise < void > {
27- const profile : UserProfile | undefined = await profileGetLoggedInAsync ( )
28+ isFetchingProfileRef . current = true
29+ let profile : UserProfile | undefined
30+ try {
31+ profile = await profileGetLoggedInAsync ( )
32+ } catch ( error ) {
33+ }
34+
35+ isFetchingProfileRef . current = false
2836 const contextData : ProfileContextData = {
2937 changePassword,
3038 initialized : true ,
@@ -67,7 +75,7 @@ export const ProfileProvider: FC<ProfileProviderProps> = (props: ProfileProvider
6775 useEffect ( ( ) => {
6876
6977 // if our profile is already initialized, no need to continue
70- if ( profileContextData . initialized ) {
78+ if ( profileContextData . initialized || isFetchingProfileRef . current ) {
7179 return
7280 }
7381
0 commit comments