@auth0/auth0-react 2.2.4 → 2.4.0

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.
package/dist/errors.d.ts CHANGED
@@ -1,12 +1,12 @@
1
- /**
2
- * An OAuth2 error will come from the authorization server and will have at least an `error` property which will
3
- * be the error code. And possibly an `error_description` property
4
- *
5
- * See: https://openid.net/specs/openid-connect-core-1_0.html#rfc.section.3.1.2.6
6
- */
7
- export declare class OAuthError extends Error {
8
- error: string;
9
- error_description?: string | undefined;
10
- constructor(error: string, error_description?: string | undefined);
11
- }
1
+ /**
2
+ * An OAuth2 error will come from the authorization server and will have at least an `error` property which will
3
+ * be the error code. And possibly an `error_description` property
4
+ *
5
+ * See: https://openid.net/specs/openid-connect-core-1_0.html#rfc.section.3.1.2.6
6
+ */
7
+ export declare class OAuthError extends Error {
8
+ error: string;
9
+ error_description?: string | undefined;
10
+ constructor(error: string, error_description?: string | undefined);
11
+ }
12
12
  //# sourceMappingURL=errors.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.tsx"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,qBAAa,UAAW,SAAQ,KAAK;IAChB,KAAK,EAAE,MAAM;IAAS,iBAAiB,CAAC;gBAAxC,KAAK,EAAE,MAAM,EAAS,iBAAiB,CAAC,oBAAQ;CAMpE"}
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.tsx"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,qBAAa,UAAW,SAAQ,KAAK;IAChB,KAAK,EAAE,MAAM;IAAS,iBAAiB,CAAC,EAAE,MAAM;gBAAhD,KAAK,EAAE,MAAM,EAAS,iBAAiB,CAAC,EAAE,MAAM,YAAA;CAMpE"}
package/dist/index.d.ts CHANGED
@@ -1,8 +1,8 @@
1
- export { default as Auth0Provider, Auth0ProviderOptions, AppState, } from './auth0-provider';
2
- export { default as useAuth0 } from './use-auth0';
3
- export { default as withAuth0, WithAuth0Props } from './with-auth0';
4
- export { default as withAuthenticationRequired, WithAuthenticationRequiredOptions, } from './with-authentication-required';
5
- export { default as Auth0Context, Auth0ContextInterface, initialContext, LogoutOptions, RedirectLoginOptions, } from './auth0-context';
6
- export { AuthorizationParams, PopupLoginOptions, PopupConfigOptions, GetTokenWithPopupOptions, LogoutUrlOptions, CacheLocation, GetTokenSilentlyOptions, IdToken, User, ICache, InMemoryCache, LocalStorageCache, Cacheable, TimeoutError, MfaRequiredError, PopupCancelledError, PopupTimeoutError, AuthenticationError, MissingRefreshTokenError, GenericError } from '@auth0/auth0-spa-js';
7
- export { OAuthError } from './errors';
1
+ export { default as Auth0Provider, Auth0ProviderOptions, AppState, } from './auth0-provider';
2
+ export { default as useAuth0 } from './use-auth0';
3
+ export { default as withAuth0, WithAuth0Props } from './with-auth0';
4
+ export { default as withAuthenticationRequired, WithAuthenticationRequiredOptions, } from './with-authentication-required';
5
+ export { default as Auth0Context, Auth0ContextInterface, initialContext, LogoutOptions, RedirectLoginOptions, } from './auth0-context';
6
+ export { AuthorizationParams, PopupLoginOptions, PopupConfigOptions, GetTokenWithPopupOptions, LogoutUrlOptions, CacheLocation, GetTokenSilentlyOptions, IdToken, User, ICache, InMemoryCache, LocalStorageCache, Cacheable, TimeoutError, MfaRequiredError, PopupCancelledError, PopupTimeoutError, AuthenticationError, MissingRefreshTokenError, GenericError } from '@auth0/auth0-spa-js';
7
+ export { OAuthError } from './errors';
8
8
  //# sourceMappingURL=index.d.ts.map
package/dist/reducer.d.ts CHANGED
@@ -1,19 +1,19 @@
1
- import { User } from '@auth0/auth0-spa-js';
2
- import { AuthState } from './auth-state';
3
- type Action = {
4
- type: 'LOGIN_POPUP_STARTED';
5
- } | {
6
- type: 'INITIALISED' | 'LOGIN_POPUP_COMPLETE' | 'GET_ACCESS_TOKEN_COMPLETE' | 'HANDLE_REDIRECT_COMPLETE';
7
- user?: User;
8
- } | {
9
- type: 'LOGOUT';
10
- } | {
11
- type: 'ERROR';
12
- error: Error;
13
- };
14
- /**
15
- * Handles how that state changes in the `useAuth0` hook.
16
- */
17
- export declare const reducer: (state: AuthState, action: Action) => AuthState;
18
- export {};
1
+ import { User } from '@auth0/auth0-spa-js';
2
+ import { AuthState } from './auth-state';
3
+ type Action = {
4
+ type: 'LOGIN_POPUP_STARTED';
5
+ } | {
6
+ type: 'INITIALISED' | 'LOGIN_POPUP_COMPLETE' | 'GET_ACCESS_TOKEN_COMPLETE' | 'HANDLE_REDIRECT_COMPLETE';
7
+ user: User | undefined;
8
+ } | {
9
+ type: 'LOGOUT';
10
+ } | {
11
+ type: 'ERROR';
12
+ error: Error;
13
+ };
14
+ /**
15
+ * Handles how that state changes in the `useAuth0` hook.
16
+ */
17
+ export declare const reducer: <TUser extends User = User>(state: AuthState<TUser>, action: Action) => AuthState<TUser>;
18
+ export {};
19
19
  //# sourceMappingURL=reducer.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"reducer.d.ts","sourceRoot":"","sources":["../src/reducer.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC,KAAK,MAAM,GACP;IAAE,IAAI,EAAE,qBAAqB,CAAA;CAAE,GAC/B;IACE,IAAI,EACA,aAAa,GACb,sBAAsB,GACtB,2BAA2B,GAC3B,0BAA0B,CAAC;IAC/B,IAAI,CAAC,EAAE,IAAI,CAAC;CACb,GACD;IAAE,IAAI,EAAE,QAAQ,CAAA;CAAE,GAClB;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,KAAK,EAAE,KAAK,CAAA;CAAE,CAAC;AAEpC;;GAEG;AACH,eAAO,MAAM,OAAO,UAAW,SAAS,UAAU,MAAM,KAAG,SAuC1D,CAAC"}
1
+ {"version":3,"file":"reducer.d.ts","sourceRoot":"","sources":["../src/reducer.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC,KAAK,MAAM,GACP;IAAE,IAAI,EAAE,qBAAqB,CAAA;CAAE,GAC/B;IACE,IAAI,EACA,aAAa,GACb,sBAAsB,GACtB,2BAA2B,GAC3B,0BAA0B,CAAC;IAC/B,IAAI,EAAE,IAAI,GAAG,SAAS,CAAC;CACxB,GACD;IAAE,IAAI,EAAE,QAAQ,CAAA;CAAE,GAClB;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,KAAK,EAAE,KAAK,CAAA;CAAE,CAAC;AAEpC;;GAEG;AACH,eAAO,MAAM,OAAO,GAAI,KAAK,SAAS,IAAI,GAAG,IAAI,EAAE,OAAO,SAAS,CAAC,KAAK,CAAC,EAAE,QAAQ,MAAM,KAAG,SAAS,CAAC,KAAK,CAuC3G,CAAC"}
@@ -1,28 +1,27 @@
1
- /// <reference types="react" />
2
- import { User } from '@auth0/auth0-spa-js';
3
- import { Auth0ContextInterface } from './auth0-context';
4
- /**
5
- * ```js
6
- * const {
7
- * // Auth state:
8
- * error,
9
- * isAuthenticated,
10
- * isLoading,
11
- * user,
12
- * // Auth methods:
13
- * getAccessTokenSilently,
14
- * getAccessTokenWithPopup,
15
- * getIdTokenClaims,
16
- * loginWithRedirect,
17
- * loginWithPopup,
18
- * logout,
19
- * } = useAuth0<TUser>();
20
- * ```
21
- *
22
- * Use the `useAuth0` hook in your components to access the auth state and methods.
23
- *
24
- * TUser is an optional type param to provide a type to the `user` field.
25
- */
26
- declare const useAuth0: <TUser extends User = User>(context?: import("react").Context<Auth0ContextInterface<User>>) => Auth0ContextInterface<TUser>;
27
- export default useAuth0;
1
+ import { User } from '@auth0/auth0-spa-js';
2
+ import { Auth0ContextInterface } from './auth0-context';
3
+ /**
4
+ * ```js
5
+ * const {
6
+ * // Auth state:
7
+ * error,
8
+ * isAuthenticated,
9
+ * isLoading,
10
+ * user,
11
+ * // Auth methods:
12
+ * getAccessTokenSilently,
13
+ * getAccessTokenWithPopup,
14
+ * getIdTokenClaims,
15
+ * loginWithRedirect,
16
+ * loginWithPopup,
17
+ * logout,
18
+ * } = useAuth0<TUser>();
19
+ * ```
20
+ *
21
+ * Use the `useAuth0` hook in your components to access the auth state and methods.
22
+ *
23
+ * TUser is an optional type param to provide a type to the `user` field.
24
+ */
25
+ declare const useAuth0: <TUser extends User = User>(context?: import("react").Context<Auth0ContextInterface<User>>) => Auth0ContextInterface<TUser>;
26
+ export default useAuth0;
28
27
  //# sourceMappingURL=use-auth0.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-auth0.d.ts","sourceRoot":"","sources":["../src/use-auth0.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAC3C,OAAqB,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAEtE;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,QAAA,MAAM,QAAQ,6HAGuC,CAAC;AAEtD,eAAe,QAAQ,CAAC"}
1
+ {"version":3,"file":"use-auth0.d.ts","sourceRoot":"","sources":["../src/use-auth0.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAC3C,OAAqB,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAEtE;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,QAAA,MAAM,QAAQ,GAAI,KAAK,SAAS,IAAI,GAAG,IAAI,EACzC,8DAAsB,KACrB,qBAAqB,CAAC,KAAK,CACuB,CAAC;AAEtD,eAAe,QAAQ,CAAC"}
package/dist/utils.d.ts CHANGED
@@ -1,10 +1,10 @@
1
- export declare const hasAuthParams: (searchParams?: string) => boolean;
2
- export declare const loginError: (error: unknown) => Error;
3
- export declare const tokenError: (error: unknown) => Error;
4
- /**
5
- * @ignore
6
- * Helper function to map the v1 `redirectUri` option to the v2 `authorizationParams.redirect_uri`
7
- * and log a warning.
8
- */
9
- export declare const deprecateRedirectUri: (options?: any) => void;
1
+ export declare const hasAuthParams: (searchParams?: string) => boolean;
2
+ export declare const loginError: (error: unknown) => Error;
3
+ export declare const tokenError: (error: unknown) => Error;
4
+ /**
5
+ * @ignore
6
+ * Helper function to map the v1 `redirectUri` option to the v2 `authorizationParams.redirect_uri`
7
+ * and log a warning.
8
+ */
9
+ export declare const deprecateRedirectUri: (options?: any) => void;
10
10
  //# sourceMappingURL=utils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.tsx"],"names":[],"mappings":"AAMA,eAAO,MAAM,aAAa,6BAA4C,OAEzC,CAAC;AA0B9B,eAAO,MAAM,UAAU,UAtBb,OAAO,KAAG,KAsBsC,CAAC;AAE3D,eAAO,MAAM,UAAU,UAxBb,OAAO,KAAG,KAwBiD,CAAC;AAEtE;;;;GAIG;AAEH,eAAO,MAAM,oBAAoB,aAAc,GAAG,SAkBjD,CAAC"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.tsx"],"names":[],"mappings":"AAMA,eAAO,MAAM,aAAa,GAAI,qBAAqC,KAAG,OAEzC,CAAC;AA0B9B,eAAO,MAAM,UAAU,UAtBb,OAAO,KAAG,KAsBsC,CAAC;AAE3D,eAAO,MAAM,UAAU,UAxBb,OAAO,KAAG,KAwBiD,CAAC;AAEtE;;;;GAIG;AAEH,eAAO,MAAM,oBAAoB,GAAI,UAAU,GAAG,SAkBjD,CAAC"}
@@ -1,29 +1,29 @@
1
- import React, { ComponentType } from 'react';
2
- import { Auth0ContextInterface } from './auth0-context';
3
- /**
4
- * Components wrapped in `withAuth0` will have an additional `auth0` prop
5
- */
6
- export interface WithAuth0Props {
7
- auth0: Auth0ContextInterface;
8
- }
9
- /**
10
- * ```jsx
11
- * class MyComponent extends Component {
12
- * render() {
13
- * // Access the auth context from the `auth0` prop
14
- * const { user } = this.props.auth0;
15
- * return <div>Hello {user.name}!</div>
16
- * }
17
- * }
18
- * // Wrap your class component in withAuth0
19
- * export default withAuth0(MyComponent);
20
- * ```
21
- *
22
- * Wrap your class components in this Higher Order Component to give them access to the Auth0Context.
23
- *
24
- * Providing a context as the second argument allows you to configure the Auth0Provider the Auth0Context
25
- * should come from f you have multiple within your application.
26
- */
27
- declare const withAuth0: <P extends WithAuth0Props>(Component: React.ComponentType<P>, context?: React.Context<Auth0ContextInterface<import("@auth0/auth0-spa-js").User>>) => React.ComponentType<Omit<P, "auth0">>;
28
- export default withAuth0;
1
+ import React, { ComponentType } from 'react';
2
+ import { Auth0ContextInterface } from './auth0-context';
3
+ /**
4
+ * Components wrapped in `withAuth0` will have an additional `auth0` prop
5
+ */
6
+ export interface WithAuth0Props {
7
+ auth0: Auth0ContextInterface;
8
+ }
9
+ /**
10
+ * ```jsx
11
+ * class MyComponent extends Component {
12
+ * render() {
13
+ * // Access the auth context from the `auth0` prop
14
+ * const { user } = this.props.auth0;
15
+ * return <div>Hello {user.name}!</div>
16
+ * }
17
+ * }
18
+ * // Wrap your class component in withAuth0
19
+ * export default withAuth0(MyComponent);
20
+ * ```
21
+ *
22
+ * Wrap your class components in this Higher Order Component to give them access to the Auth0Context.
23
+ *
24
+ * Providing a context as the second argument allows you to configure the Auth0Provider the Auth0Context
25
+ * should come from f you have multiple within your application.
26
+ */
27
+ declare const withAuth0: <P extends WithAuth0Props>(Component: ComponentType<P>, context?: React.Context<Auth0ContextInterface<import("@auth0/auth0-spa-js").User>>) => ComponentType<Omit<P, keyof WithAuth0Props>>;
28
+ export default withAuth0;
29
29
  //# sourceMappingURL=with-auth0.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"with-auth0.d.ts","sourceRoot":"","sources":["../src/with-auth0.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAC7C,OAAqB,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAEtE;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,qBAAqB,CAAC;CAC9B;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,QAAA,MAAM,SAAS,4LAad,CAAC;AAEF,eAAe,SAAS,CAAC"}
1
+ {"version":3,"file":"with-auth0.d.ts","sourceRoot":"","sources":["../src/with-auth0.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAC7C,OAAqB,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAEtE;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,qBAAqB,CAAC;CAC9B;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,QAAA,MAAM,SAAS,GAAI,CAAC,SAAS,cAAc,EACzC,WAAW,aAAa,CAAC,CAAC,CAAC,EAC3B,kFAAsB,KACrB,aAAa,CAAC,IAAI,CAAC,CAAC,EAAE,MAAM,cAAc,CAAC,CAU7C,CAAC;AAEF,eAAe,SAAS,CAAC"}
@@ -1,77 +1,77 @@
1
- import React, { ComponentType, FC } from 'react';
2
- import { Auth0ContextInterface, RedirectLoginOptions } from './auth0-context';
3
- /**
4
- * Options for the withAuthenticationRequired Higher Order Component
5
- */
6
- export interface WithAuthenticationRequiredOptions {
7
- /**
8
- * ```js
9
- * withAuthenticationRequired(Profile, {
10
- * returnTo: '/profile'
11
- * })
12
- * ```
13
- *
14
- * or
15
- *
16
- * ```js
17
- * withAuthenticationRequired(Profile, {
18
- * returnTo: () => window.location.hash.substr(1)
19
- * })
20
- * ```
21
- *
22
- * Add a path for the `onRedirectCallback` handler to return the user to after login.
23
- */
24
- returnTo?: string | (() => string);
25
- /**
26
- * ```js
27
- * withAuthenticationRequired(Profile, {
28
- * onRedirecting: () => <div>Redirecting you to the login...</div>
29
- * })
30
- * ```
31
- *
32
- * Render a message to show that the user is being redirected to the login.
33
- */
34
- onRedirecting?: () => JSX.Element;
35
- /**
36
- * ```js
37
- * withAuthenticationRequired(Profile, {
38
- * onBeforeAuthentication: () => { analyticsLibrary.track('login_triggered'); }
39
- * })
40
- * ```
41
- *
42
- * Allows executing logic before the user is redirected to the login page.
43
- */
44
- onBeforeAuthentication?: () => Promise<void>;
45
- /**
46
- * ```js
47
- * withAuthenticationRequired(Profile, {
48
- * loginOptions: {
49
- * appState: {
50
- * customProp: 'foo'
51
- * }
52
- * }
53
- * })
54
- * ```
55
- *
56
- * Pass additional login options, like extra `appState` to the login page.
57
- * This will be merged with the `returnTo` option used by the `onRedirectCallback` handler.
58
- */
59
- loginOptions?: RedirectLoginOptions;
60
- /**
61
- * The context to be used when calling useAuth0, this should only be provided if you are using multiple Auth0Providers
62
- * within your application and you wish to tie a specific component to a Auth0Provider other than the Auth0Provider
63
- * associated with the default Auth0Context.
64
- */
65
- context?: React.Context<Auth0ContextInterface>;
66
- }
67
- /**
68
- * ```js
69
- * const MyProtectedComponent = withAuthenticationRequired(MyComponent);
70
- * ```
71
- *
72
- * When you wrap your components in this Higher Order Component and an anonymous user visits your component
73
- * they will be redirected to the login page; after login they will be returned to the page they were redirected from.
74
- */
75
- declare const withAuthenticationRequired: <P extends object>(Component: React.ComponentType<P>, options?: WithAuthenticationRequiredOptions) => React.FC<P>;
76
- export default withAuthenticationRequired;
1
+ import React, { ComponentType, FC } from 'react';
2
+ import { Auth0ContextInterface, RedirectLoginOptions } from './auth0-context';
3
+ /**
4
+ * Options for the withAuthenticationRequired Higher Order Component
5
+ */
6
+ export interface WithAuthenticationRequiredOptions {
7
+ /**
8
+ * ```js
9
+ * withAuthenticationRequired(Profile, {
10
+ * returnTo: '/profile'
11
+ * })
12
+ * ```
13
+ *
14
+ * or
15
+ *
16
+ * ```js
17
+ * withAuthenticationRequired(Profile, {
18
+ * returnTo: () => window.location.hash.substr(1)
19
+ * })
20
+ * ```
21
+ *
22
+ * Add a path for the `onRedirectCallback` handler to return the user to after login.
23
+ */
24
+ returnTo?: string | (() => string);
25
+ /**
26
+ * ```js
27
+ * withAuthenticationRequired(Profile, {
28
+ * onRedirecting: () => <div>Redirecting you to the login...</div>
29
+ * })
30
+ * ```
31
+ *
32
+ * Render a message to show that the user is being redirected to the login.
33
+ */
34
+ onRedirecting?: () => React.JSX.Element;
35
+ /**
36
+ * ```js
37
+ * withAuthenticationRequired(Profile, {
38
+ * onBeforeAuthentication: () => { analyticsLibrary.track('login_triggered'); }
39
+ * })
40
+ * ```
41
+ *
42
+ * Allows executing logic before the user is redirected to the login page.
43
+ */
44
+ onBeforeAuthentication?: () => Promise<void>;
45
+ /**
46
+ * ```js
47
+ * withAuthenticationRequired(Profile, {
48
+ * loginOptions: {
49
+ * appState: {
50
+ * customProp: 'foo'
51
+ * }
52
+ * }
53
+ * })
54
+ * ```
55
+ *
56
+ * Pass additional login options, like extra `appState` to the login page.
57
+ * This will be merged with the `returnTo` option used by the `onRedirectCallback` handler.
58
+ */
59
+ loginOptions?: RedirectLoginOptions;
60
+ /**
61
+ * The context to be used when calling useAuth0, this should only be provided if you are using multiple Auth0Providers
62
+ * within your application and you wish to tie a specific component to a Auth0Provider other than the Auth0Provider
63
+ * associated with the default Auth0Context.
64
+ */
65
+ context?: React.Context<Auth0ContextInterface>;
66
+ }
67
+ /**
68
+ * ```js
69
+ * const MyProtectedComponent = withAuthenticationRequired(MyComponent);
70
+ * ```
71
+ *
72
+ * When you wrap your components in this Higher Order Component and an anonymous user visits your component
73
+ * they will be redirected to the login page; after login they will be returned to the page they were redirected from.
74
+ */
75
+ declare const withAuthenticationRequired: <P extends object>(Component: ComponentType<P>, options?: WithAuthenticationRequiredOptions) => FC<P>;
76
+ export default withAuthenticationRequired;
77
77
  //# sourceMappingURL=with-authentication-required.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"with-authentication-required.d.ts","sourceRoot":"","sources":["../src/with-authentication-required.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,aAAa,EAAa,EAAE,EAAE,MAAM,OAAO,CAAC;AAE5D,OAAqB,EACnB,qBAAqB,EACrB,oBAAoB,EACrB,MAAM,iBAAiB,CAAC;AAkBzB;;GAEG;AACH,MAAM,WAAW,iCAAiC;IAChD;;;;;;;;;;;;;;;;OAgBG;IACH,QAAQ,CAAC,EAAE,MAAM,GAAG,CAAC,MAAM,MAAM,CAAC,CAAC;IACnC;;;;;;;;OAQG;IACH,aAAa,CAAC,EAAE,MAAM,GAAG,CAAC,OAAO,CAAC;IAClC;;;;;;;;OAQG;IACH,sBAAsB,CAAC,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAC7C;;;;;;;;;;;;;OAaG;IACH,YAAY,CAAC,EAAE,oBAAoB,CAAC;IACpC;;;;OAIG;IACH,OAAO,CAAC,EAAE,KAAK,CAAC,OAAO,CAAC,qBAAqB,CAAC,CAAC;CAChD;AAED;;;;;;;GAOG;AACH,QAAA,MAAM,0BAA0B,kEAErB,iCAAiC,gBAwC3C,CAAC;AAEF,eAAe,0BAA0B,CAAC"}
1
+ {"version":3,"file":"with-authentication-required.d.ts","sourceRoot":"","sources":["../src/with-authentication-required.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,aAAa,EAAa,EAAE,EAAE,MAAM,OAAO,CAAC;AAE5D,OAAqB,EACnB,qBAAqB,EACrB,oBAAoB,EACrB,MAAM,iBAAiB,CAAC;AAkBzB;;GAEG;AACH,MAAM,WAAW,iCAAiC;IAChD;;;;;;;;;;;;;;;;OAgBG;IACH,QAAQ,CAAC,EAAE,MAAM,GAAG,CAAC,MAAM,MAAM,CAAC,CAAC;IACnC;;;;;;;;OAQG;IACH,aAAa,CAAC,EAAE,MAAM,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC;IACxC;;;;;;;;OAQG;IACH,sBAAsB,CAAC,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAC7C;;;;;;;;;;;;;OAaG;IACH,YAAY,CAAC,EAAE,oBAAoB,CAAC;IACpC;;;;OAIG;IACH,OAAO,CAAC,EAAE,KAAK,CAAC,OAAO,CAAC,qBAAqB,CAAC,CAAC;CAChD;AAED;;;;;;;GAOG;AACH,QAAA,MAAM,0BAA0B,GAAI,CAAC,SAAS,MAAM,EAClD,WAAW,aAAa,CAAC,CAAC,CAAC,EAC3B,UAAS,iCAAsC,KAC9C,EAAE,CAAC,CAAC,CAuCN,CAAC;AAEF,eAAe,0BAA0B,CAAC"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "author": "Auth0",
3
3
  "name": "@auth0/auth0-react",
4
- "version": "2.2.4",
4
+ "version": "2.4.0",
5
5
  "description": "Auth0 SDK for React Single Page Applications (SPA)",
6
6
  "keywords": [
7
7
  "auth0",
@@ -54,29 +54,28 @@
54
54
  "@rollup/plugin-node-resolve": "^15.0.1",
55
55
  "@rollup/plugin-replace": "^5.0.1",
56
56
  "@rollup/plugin-terser": "^0.4.3",
57
- "@testing-library/jest-dom": "^5.16.5",
58
- "@testing-library/react": "^14.0.0",
59
- "@testing-library/react-hooks": "^7.0.2",
60
- "@types/jest": "^29.2.3",
61
- "@types/react": "^18.2.27",
62
- "@types/react-dom": "^18.2.12",
63
- "@typescript-eslint/eslint-plugin": "^5.45.0",
64
- "@typescript-eslint/parser": "^5.45.0",
57
+ "@testing-library/dom": "^10.4.0",
58
+ "@testing-library/jest-dom": "6.6.3",
59
+ "@testing-library/react": "16.1.0",
60
+ "@types/jest": "^29.5.14",
61
+ "@types/react": "19.1.8",
62
+ "@types/react-dom": "19.1.6",
63
+ "@typescript-eslint/eslint-plugin": "^8.36.0",
64
+ "@typescript-eslint/parser": "^8.36.0",
65
65
  "browserstack-cypress-cli": "^1.19.1",
66
66
  "cypress": "^13.1.0",
67
67
  "eslint": "^8.28.0",
68
68
  "eslint-plugin-react": "^7.31.11",
69
69
  "eslint-plugin-react-hooks": "^4.6.0",
70
70
  "husky": "^8.0.3",
71
- "jest": "^29.3.1",
71
+ "jest": "^29.7.0",
72
72
  "jest-environment-jsdom": "^29.3.1",
73
73
  "jest-junit": "^15.0.0",
74
- "oidc-provider": "^8.0.0",
74
+ "oidc-provider": "^8.8.1",
75
75
  "prettier": "^2.8.1",
76
76
  "pretty-quick": "^3.1.3",
77
- "react": "^18.2.0",
78
- "react-dom": "^18.2.0",
79
- "react-test-renderer": "^18.2.0",
77
+ "react": "19.1.0",
78
+ "react-dom": "19.1.0",
80
79
  "rollup": "^3.7.0",
81
80
  "rollup-plugin-analyzer": "^4.0.0",
82
81
  "rollup-plugin-delete": "^2.0.0",
@@ -86,16 +85,16 @@
86
85
  "rollup-plugin-serve": "^2.0.2",
87
86
  "rollup-plugin-typescript2": "^0.36.0",
88
87
  "start-server-and-test": "^2.0",
89
- "ts-jest": "^29.0.3",
90
- "tslib": "^2.4.1",
91
- "typedoc": "^0.25.3",
92
- "typescript": "^4.9.4"
88
+ "ts-jest": "^29.4.0",
89
+ "tslib": "^2.8.1",
90
+ "typedoc": "^0.28.7",
91
+ "typescript": "^5.8.3"
93
92
  },
94
93
  "peerDependencies": {
95
- "react": "^16.11.0 || ^17 || ^18",
96
- "react-dom": "^16.11.0 || ^17 || ^18"
94
+ "react": "^16.11.0 || ^17 || ^18 || ^19",
95
+ "react-dom": "^16.11.0 || ^17 || ^18 || ^19"
97
96
  },
98
97
  "dependencies": {
99
- "@auth0/auth0-spa-js": "^2.1.3"
98
+ "@auth0/auth0-spa-js": "^2.2.0"
100
99
  }
101
100
  }
@@ -4,10 +4,10 @@ import { User } from '@auth0/auth0-spa-js';
4
4
  * The auth state which, when combined with the auth methods, make up the return object of the `useAuth0` hook.
5
5
  */
6
6
  export interface AuthState<TUser extends User = User> {
7
- error?: Error;
7
+ error: Error | undefined;
8
8
  isAuthenticated: boolean;
9
9
  isLoading: boolean;
10
- user?: TUser;
10
+ user: TUser | undefined;
11
11
  }
12
12
 
13
13
  /**
@@ -16,4 +16,6 @@ export interface AuthState<TUser extends User = User> {
16
16
  export const initialAuthState: AuthState = {
17
17
  isAuthenticated: false,
18
18
  isLoading: true,
19
+ error: undefined,
20
+ user: undefined,
19
21
  };
@@ -14,9 +14,9 @@ import { createContext } from 'react';
14
14
  import { AuthState, initialAuthState } from './auth-state';
15
15
  import { AppState } from './auth0-provider';
16
16
 
17
- // eslint-disable-next-line @typescript-eslint/no-empty-interface
17
+ // eslint-disable-next-line @typescript-eslint/no-empty-object-type
18
18
  export interface LogoutOptions extends Omit<SPALogoutOptions, 'onRedirect'> {}
19
- // eslint-disable-next-line @typescript-eslint/no-empty-interface
19
+ // eslint-disable-next-line @typescript-eslint/no-empty-object-type
20
20
  export interface RedirectLoginOptions<TAppState = AppState>
21
21
  extends Omit<SPARedirectLoginOptions<TAppState>, 'onRedirect'> {}
22
22
 
@@ -38,7 +38,9 @@ export interface Auth0ContextInterface<TUser extends User = User>
38
38
  *
39
39
  * If refresh tokens are used, the token endpoint is called directly with the
40
40
  * 'refresh_token' grant. If no refresh token is available to make this call,
41
- * the SDK falls back to using an iframe to the '/authorize' URL.
41
+ * the SDK will only fall back to using an iframe to the '/authorize' URL if
42
+ * the `useRefreshTokensFallback` setting has been set to `true`. By default this
43
+ * setting is `false`.
42
44
  *
43
45
  * This method may use a web worker to perform the token call if the in-memory
44
46
  * cache is used.
@@ -28,7 +28,7 @@ import {
28
28
  deprecateRedirectUri,
29
29
  } from './utils';
30
30
  import { reducer } from './reducer';
31
- import { initialAuthState } from './auth-state';
31
+ import { initialAuthState, type AuthState } from './auth-state';
32
32
 
33
33
  /**
34
34
  * The state of the application before the user was redirected to the login page.
@@ -41,7 +41,7 @@ export type AppState = {
41
41
  /**
42
42
  * The main configuration to instantiate the `Auth0Provider`.
43
43
  */
44
- export interface Auth0ProviderOptions extends Auth0ClientOptions {
44
+ export interface Auth0ProviderOptions<TUser extends User = User> extends Auth0ClientOptions {
45
45
  /**
46
46
  * The child nodes your Provider has wrapped
47
47
  */
@@ -51,7 +51,7 @@ export interface Auth0ProviderOptions extends Auth0ClientOptions {
51
51
  * It uses `window.history` but you might want to overwrite this if you are using a custom router, like `react-router-dom`
52
52
  * See the EXAMPLES.md for more info.
53
53
  */
54
- onRedirectCallback?: (appState?: AppState, user?: User) => void;
54
+ onRedirectCallback?: (appState?: AppState, user?: TUser) => void;
55
55
  /**
56
56
  * By default, if the page url has code/state params, the SDK will treat them as Auth0's and attempt to exchange the
57
57
  * code for a token. In some cases the code might be for something else (another OAuth SDK perhaps). In these
@@ -83,7 +83,7 @@ export interface Auth0ProviderOptions extends Auth0ClientOptions {
83
83
  *
84
84
  * For a sample on using multiple Auth0Providers review the [React Account Linking Sample](https://github.com/auth0-samples/auth0-link-accounts-sample/tree/react-variant)
85
85
  */
86
- context?: React.Context<Auth0ContextInterface>;
86
+ context?: React.Context<Auth0ContextInterface<TUser>>;
87
87
  }
88
88
 
89
89
  /**
@@ -116,7 +116,7 @@ const defaultOnRedirectCallback = (appState?: AppState): void => {
116
116
  window.history.replaceState(
117
117
  {},
118
118
  document.title,
119
- appState?.returnTo || window.location.pathname
119
+ appState?.returnTo ?? window.location.pathname
120
120
  );
121
121
  };
122
122
 
@@ -125,14 +125,14 @@ const defaultOnRedirectCallback = (appState?: AppState): void => {
125
125
  * <Auth0Provider
126
126
  * domain={domain}
127
127
  * clientId={clientId}
128
- * authorizationParams={{ redirect_uri: window.location.origin }}}>
128
+ * authorizationParams={{ redirect_uri: window.location.origin }}>
129
129
  * <MyApp />
130
130
  * </Auth0Provider>
131
131
  * ```
132
132
  *
133
133
  * Provides the Auth0Context to its child components.
134
134
  */
135
- const Auth0Provider = (opts: Auth0ProviderOptions): JSX.Element => {
135
+ const Auth0Provider = <TUser extends User = User>(opts: Auth0ProviderOptions<TUser>) => {
136
136
  const {
137
137
  children,
138
138
  skipRedirectCallback,
@@ -143,9 +143,14 @@ const Auth0Provider = (opts: Auth0ProviderOptions): JSX.Element => {
143
143
  const [client] = useState(
144
144
  () => new Auth0Client(toAuth0ClientOptions(clientOpts))
145
145
  );
146
- const [state, dispatch] = useReducer(reducer, initialAuthState);
146
+ const [state, dispatch] = useReducer(reducer<TUser>, initialAuthState as AuthState<TUser>);
147
147
  const didInitialise = useRef(false);
148
148
 
149
+ const handleError = useCallback((error: Error) => {
150
+ dispatch({ type: 'ERROR', error });
151
+ return error;
152
+ }, []);
153
+
149
154
  useEffect(() => {
150
155
  if (didInitialise.current) {
151
156
  return;
@@ -153,7 +158,7 @@ const Auth0Provider = (opts: Auth0ProviderOptions): JSX.Element => {
153
158
  didInitialise.current = true;
154
159
  (async (): Promise<void> => {
155
160
  try {
156
- let user: User | undefined;
161
+ let user: TUser | undefined;
157
162
  if (hasAuthParams() && !skipRedirectCallback) {
158
163
  const { appState } = await client.handleRedirectCallback();
159
164
  user = await client.getUser();
@@ -164,10 +169,10 @@ const Auth0Provider = (opts: Auth0ProviderOptions): JSX.Element => {
164
169
  }
165
170
  dispatch({ type: 'INITIALISED', user });
166
171
  } catch (error) {
167
- dispatch({ type: 'ERROR', error: loginError(error) });
172
+ handleError(loginError(error));
168
173
  }
169
174
  })();
170
- }, [client, onRedirectCallback, skipRedirectCallback]);
175
+ }, [client, onRedirectCallback, skipRedirectCallback, handleError]);
171
176
 
172
177
  const loginWithRedirect = useCallback(
173
178
  (opts?: RedirectLoginOptions): Promise<void> => {
@@ -187,13 +192,13 @@ const Auth0Provider = (opts: Auth0ProviderOptions): JSX.Element => {
187
192
  try {
188
193
  await client.loginWithPopup(options, config);
189
194
  } catch (error) {
190
- dispatch({ type: 'ERROR', error: loginError(error) });
195
+ handleError(loginError(error));
191
196
  return;
192
197
  }
193
198
  const user = await client.getUser();
194
199
  dispatch({ type: 'LOGIN_POPUP_COMPLETE', user });
195
200
  },
196
- [client]
201
+ [client, handleError]
197
202
  );
198
203
 
199
204
  const logout = useCallback(
@@ -267,7 +272,7 @@ const Auth0Provider = (opts: Auth0ProviderOptions): JSX.Element => {
267
272
  [client]
268
273
  );
269
274
 
270
- const contextValue = useMemo<Auth0ContextInterface<User>>(() => {
275
+ const contextValue = useMemo<Auth0ContextInterface<TUser>>(() => {
271
276
  return {
272
277
  ...state,
273
278
  getAccessTokenSilently,