@asgardeo/auth-react 1.1.5 → 1.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -17,14 +17,15 @@
17
17
  */
18
18
 
19
19
  import {
20
+ AsgardeoAuthException,
21
+ AsgardeoSPAClient,
20
22
  AuthClientConfig,
21
23
  BasicUserInfo,
22
24
  FetchResponse,
23
25
  Hooks,
24
26
  HttpRequestConfig,
25
27
  SPAUtils,
26
- SignInConfig,
27
- AsgardeoAuthException
28
+ SignInConfig
28
29
  } from "@asgardeo/auth-spa";
29
30
  import { SPACustomGrantConfig } from "@asgardeo/auth-spa/src/models/request-custom-grant";
30
31
  import React, {
@@ -48,8 +49,6 @@ const defaultConfig: Partial<ReactConfig> = {
48
49
  disableTrySignInSilently: true
49
50
  };
50
51
 
51
- const AuthClient = new AuthAPI();
52
-
53
52
  /**
54
53
  * Authentication Context to hold global states in react components.
55
54
  */
@@ -60,16 +59,20 @@ interface AuthProviderPropsInterface {
60
59
  fallback?: ReactNode;
61
60
  getAuthParams?: () => Promise<AuthParams>;
62
61
  onSignOut?: () => void;
62
+ spaclient?: AsgardeoSPAClient;
63
63
  }
64
64
 
65
65
  const AuthProvider: FunctionComponent<PropsWithChildren<AuthProviderPropsInterface>> = (
66
66
  props: PropsWithChildren<AuthProviderPropsInterface>
67
67
  ) => {
68
+ const { children, config: passedConfig, fallback, getAuthParams, onSignOut, spaclient } = props;
69
+ const AuthClient: AuthAPI = useMemo(() => {
70
+ return new AuthAPI(spaclient);
71
+ }, [ props?.spaclient ]);
72
+
68
73
  const [ state, dispatch ] = useState<AuthStateInterface>(AuthClient.getState());
69
74
  const [ initialized, setInitialized ] = useState(false);
70
75
 
71
- const { children, config: passedConfig, fallback, getAuthParams, onSignOut } = props;
72
-
73
76
  const config = useMemo(
74
77
  (): AuthReactConfig => ({ ...defaultConfig, ...passedConfig }), [ passedConfig ]
75
78
  );
@@ -179,7 +182,7 @@ const AuthProvider: FunctionComponent<PropsWithChildren<AuthProviderPropsInterfa
179
182
  authParams?.state
180
183
  );
181
184
  } catch(error) {
182
- if(error instanceof AsgardeoAuthException) {
185
+ if(error && Object.prototype.hasOwnProperty.call(error, "code")) {
183
186
  setError(error);
184
187
  }
185
188
  }
@@ -206,7 +209,9 @@ const AuthProvider: FunctionComponent<PropsWithChildren<AuthProviderPropsInterfa
206
209
  .catch((error) => {
207
210
  // TODO: Add logs when a logger is available.
208
211
  // Tracked here https://github.com/asgardeo/asgardeo-auth-js-sdk/issues/151.
209
- throw error;
212
+ if(error && Object.prototype.hasOwnProperty.call(error, "code")) {
213
+ setError(error);
214
+ }
210
215
  });
211
216
  })();
212
217
 
@@ -250,4 +255,4 @@ const useAuthContext = (): AuthContextInterface => {
250
255
  return useContext(AuthContext);
251
256
  };
252
257
 
253
- export { AuthClient, AuthProvider, useAuthContext };
258
+ export { AuthProvider, useAuthContext };