1+ import  {  oryClient  }  from  '@/auth/ory' ; 
2+ import  {  workosClient  }  from  '@/auth/workos' ; 
13import  {  getOrInitializeActiveTeam  }  from  '@/shared/utils/activeTeam' ; 
24import  {  useEffect  }  from  'react' ; 
35
@@ -32,19 +34,12 @@ export interface AuthClient {
3234  authenticateWithMagicCode ( args : {  email : string ;  code : string  } ) : Promise < void > ; 
3335} 
3436
35- let  cachedAuthClient : Promise < AuthClient >  |  AuthClient  |  null  =  null ; 
36- const  getAuthClient  =  async  ( ) : Promise < AuthClient >  =>  { 
37-   if  ( cachedAuthClient )  { 
38-     return  await  cachedAuthClient ; 
39-   } 
40- 
37+ const  getAuthClient  =  ( ) : AuthClient  =>  { 
4138  switch  ( AUTH_TYPE )  { 
4239    case  'ory' :
43-       cachedAuthClient  =  ( await  import ( '@/auth/ory' ) ) . oryClient ; 
44-       return  cachedAuthClient ; 
40+       return  oryClient ; 
4541    case  'workos' :
46-       cachedAuthClient  =  ( await  import ( '@/auth/workos' ) ) . workosClient ; 
47-       return  cachedAuthClient ; 
42+       return  workosClient ; 
4843    default :
4944      throw  new  Error ( `Unsupported auth type in getAuthClient(): ${ AUTH_TYPE }  ) ; 
5045  } 
@@ -53,59 +48,59 @@ const getAuthClient = async (): Promise<AuthClient> => {
5348// Create a proxy client that lazily loads the actual client 
5449export  const  authClient : AuthClient  =  { 
5550  async  isAuthenticated ( )  { 
56-     const  client  =  await   getAuthClient ( ) ; 
51+     const  client  =  getAuthClient ( ) ; 
5752    return  client . isAuthenticated ( ) ; 
5853  } , 
5954  async  user ( )  { 
60-     const  client  =  await   getAuthClient ( ) ; 
55+     const  client  =  getAuthClient ( ) ; 
6156    return  client . user ( ) ; 
6257  } , 
6358  async  login ( args : {  redirectTo : string ;  isSignupFlow ?: boolean ;  href : string  } )  { 
64-     const  client  =  await   getAuthClient ( ) ; 
59+     const  client  =  getAuthClient ( ) ; 
6560    return  client . login ( args ) ; 
6661  } , 
6762  async  handleSigninRedirect ( href : string )  { 
68-     const  client  =  await   getAuthClient ( ) ; 
63+     const  client  =  getAuthClient ( ) ; 
6964    return  client . handleSigninRedirect ( href ) ; 
7065  } , 
7166  async  logout ( )  { 
72-     const  client  =  await   getAuthClient ( ) ; 
67+     const  client  =  getAuthClient ( ) ; 
7368    return  client . logout ( ) ; 
7469  } , 
7570  async  getTokenOrRedirect ( skipRedirect ?: boolean )  { 
76-     const  client  =  await   getAuthClient ( ) ; 
71+     const  client  =  getAuthClient ( ) ; 
7772    return  client . getTokenOrRedirect ( skipRedirect ) ; 
7873  } , 
7974  async  loginWithPassword ( args : {  email : string ;  password : string  } )  { 
80-     const  client  =  await   getAuthClient ( ) ; 
75+     const  client  =  getAuthClient ( ) ; 
8176    return  client . loginWithPassword ( args ) ; 
8277  } , 
8378  async  loginWithOAuth ( args : {  provider : OAuthProvider ;  redirectTo : string  } )  { 
84-     const  client  =  await   getAuthClient ( ) ; 
79+     const  client  =  getAuthClient ( ) ; 
8580    return  client . loginWithOAuth ( args ) ; 
8681  } , 
8782  async  signupWithPassword ( args : {  email : string ;  password : string ;  firstName : string ;  lastName : string  } )  { 
88-     const  client  =  await   getAuthClient ( ) ; 
83+     const  client  =  getAuthClient ( ) ; 
8984    return  client . signupWithPassword ( args ) ; 
9085  } , 
9186  async  verifyEmail ( args : {  pendingAuthenticationToken : string ;  code : string  } )  { 
92-     const  client  =  await   getAuthClient ( ) ; 
87+     const  client  =  getAuthClient ( ) ; 
9388    return  client . verifyEmail ( args ) ; 
9489  } , 
9590  async  sendResetPassword ( args : {  email : string  } )  { 
96-     const  client  =  await   getAuthClient ( ) ; 
91+     const  client  =  getAuthClient ( ) ; 
9792    return  client . sendResetPassword ( args ) ; 
9893  } , 
9994  async  resetPassword ( args : {  token : string ;  password : string  } )  { 
100-     const  client  =  await   getAuthClient ( ) ; 
95+     const  client  =  getAuthClient ( ) ; 
10196    return  client . resetPassword ( args ) ; 
10297  } , 
10398  async  sendMagicAuthCode ( args : {  email : string  } )  { 
104-     const  client  =  await   getAuthClient ( ) ; 
99+     const  client  =  getAuthClient ( ) ; 
105100    return  client . sendMagicAuthCode ( args ) ; 
106101  } , 
107102  async  authenticateWithMagicCode ( args : {  email : string ;  code : string  } )  { 
108-     const  client  =  await   getAuthClient ( ) ; 
103+     const  client  =  getAuthClient ( ) ; 
109104    return  client . authenticateWithMagicCode ( args ) ; 
110105  } , 
111106} ; 
0 commit comments