@@ -4,7 +4,7 @@ import { FlagValues } from 'flags/react'
44import  {  createContext ,  PropsWithChildren ,  useContext ,  useEffect ,  useState  }  from  'react' 
55
66import  {  components  }  from  'api-types' 
7- import  {  useUser  }  from  './auth' 
7+ import  {  useAuth  }  from  './auth' 
88import  {  getFlags  as  getDefaultConfigCatFlags  }  from  './configcat' 
99import  {  hasConsented  }  from  './consent-state' 
1010import  {  get ,  post  }  from  './fetchWrappers' 
@@ -72,7 +72,8 @@ export const FeatureFlagProvider = ({
7272    userEmail ?: string 
7373  )  =>  Promise < {  settingKey : string ;  settingValue : boolean  |  number  |  string  |  null  |  undefined  } [ ] > 
7474} > )  =>  { 
75-   const  user  =  useUser ( ) 
75+   const  {  session,  isLoading }  =  useAuth ( ) 
76+   const  userEmail  =  session ?. user ?. email 
7677
7778  const  [ store ,  setStore ]  =  useState < FeatureFlagContextType > ( { 
7879    API_URL , 
@@ -85,7 +86,7 @@ export const FeatureFlagProvider = ({
8586    let  mounted  =  true 
8687
8788    async  function  processFlags ( )  { 
88-       if  ( ! enabled )  return 
89+       if  ( ! enabled   ||   isLoading )  return 
8990
9091      const  loadPHFlags  = 
9192        ( enabled  ===  true  ||  ( typeof  enabled  ===  'object'  &&  enabled . ph ) )  &&  ! ! API_URL 
@@ -98,8 +99,8 @@ export const FeatureFlagProvider = ({
9899        loadPHFlags  ? getFeatureFlags ( API_URL )  : Promise . resolve ( { } ) , 
99100        loadCCFlags 
100101          ? typeof  getConfigCatFlags  ===  'function' 
101-             ? getConfigCatFlags ( user ?. email ) 
102-             : getDefaultConfigCatFlags ( user ?. email ) 
102+             ? getConfigCatFlags ( userEmail ) 
103+             : getDefaultConfigCatFlags ( userEmail ) 
103104          : Promise . resolve ( [ ] ) , 
104105      ] ) 
105106
@@ -139,7 +140,7 @@ export const FeatureFlagProvider = ({
139140    return  ( )  =>  { 
140141      mounted  =  false 
141142    } 
142-   } ,  [ enabled ,  user ?. email ] ) 
143+   } ,  [ enabled ,  isLoading ,   userEmail ] ) 
143144
144145  return  ( 
145146    < FeatureFlagContext . Provider  value = { store } > 
0 commit comments