@auth0/auth0-react 2.3.0 → 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/auth-state.d.ts +14 -14
- package/dist/auth-state.d.ts.map +1 -1
- package/dist/auth0-context.d.ts +134 -135
- package/dist/auth0-context.d.ts.map +1 -1
- package/dist/auth0-provider.d.ts +71 -71
- package/dist/auth0-provider.d.ts.map +1 -1
- package/dist/auth0-react.cjs.js +453 -436
- package/dist/auth0-react.cjs.js.map +1 -1
- package/dist/auth0-react.esm.js +451 -434
- package/dist/auth0-react.esm.js.map +1 -1
- package/dist/auth0-react.js +453 -436
- package/dist/auth0-react.js.map +1 -1
- package/dist/auth0-react.min.js +1 -1
- package/dist/auth0-react.min.js.map +1 -1
- package/dist/errors.d.ts +11 -11
- package/dist/errors.d.ts.map +1 -1
- package/dist/index.d.ts +7 -7
- package/dist/reducer.d.ts +18 -18
- package/dist/reducer.d.ts.map +1 -1
- package/dist/use-auth0.d.ts +26 -27
- package/dist/use-auth0.d.ts.map +1 -1
- package/dist/utils.d.ts +9 -9
- package/dist/utils.d.ts.map +1 -1
- package/dist/with-auth0.d.ts +28 -28
- package/dist/with-auth0.d.ts.map +1 -1
- package/dist/with-authentication-required.d.ts +76 -76
- package/dist/with-authentication-required.d.ts.map +1 -1
- package/package.json +16 -16
- package/src/auth-state.tsx +4 -2
- package/src/auth0-context.tsx +2 -2
- package/src/auth0-provider.tsx +10 -10
- package/src/errors.tsx +1 -1
- package/src/reducer.tsx +4 -4
- package/src/utils.tsx +1 -1
- package/src/with-authentication-required.tsx +2 -2
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
|
package/dist/errors.d.ts.map
CHANGED
|
@@ -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;
|
|
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
|
|
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
|
|
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
|
package/dist/reducer.d.ts.map
CHANGED
|
@@ -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,
|
|
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"}
|
package/dist/use-auth0.d.ts
CHANGED
|
@@ -1,28 +1,27 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
package/dist/use-auth0.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-auth0.d.ts","sourceRoot":"","sources":["../src/use-auth0.tsx"],"names":[],"mappings":"
|
|
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
|
package/dist/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.tsx"],"names":[],"mappings":"AAMA,eAAO,MAAM,aAAa,
|
|
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"}
|
package/dist/with-auth0.d.ts
CHANGED
|
@@ -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:
|
|
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
|
package/dist/with-auth0.d.ts.map
CHANGED
|
@@ -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,
|
|
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?: () => 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:
|
|
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,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,
|
|
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.
|
|
4
|
+
"version": "2.4.0",
|
|
5
5
|
"description": "Auth0 SDK for React Single Page Applications (SPA)",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"auth0",
|
|
@@ -54,28 +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/dom": "^10.4.0",
|
|
57
58
|
"@testing-library/jest-dom": "6.6.3",
|
|
58
59
|
"@testing-library/react": "16.1.0",
|
|
59
|
-
"@
|
|
60
|
-
"@types/
|
|
61
|
-
"@types/react": "19.
|
|
62
|
-
"@
|
|
63
|
-
"@typescript-eslint/
|
|
64
|
-
"@typescript-eslint/parser": "^5.45.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.
|
|
71
|
+
"jest": "^29.7.0",
|
|
72
72
|
"jest-environment-jsdom": "^29.3.1",
|
|
73
73
|
"jest-junit": "^15.0.0",
|
|
74
|
-
"oidc-provider": "^8.
|
|
74
|
+
"oidc-provider": "^8.8.1",
|
|
75
75
|
"prettier": "^2.8.1",
|
|
76
76
|
"pretty-quick": "^3.1.3",
|
|
77
|
-
"react": "
|
|
78
|
-
"react-dom": "19.
|
|
77
|
+
"react": "19.1.0",
|
|
78
|
+
"react-dom": "19.1.0",
|
|
79
79
|
"rollup": "^3.7.0",
|
|
80
80
|
"rollup-plugin-analyzer": "^4.0.0",
|
|
81
81
|
"rollup-plugin-delete": "^2.0.0",
|
|
@@ -85,16 +85,16 @@
|
|
|
85
85
|
"rollup-plugin-serve": "^2.0.2",
|
|
86
86
|
"rollup-plugin-typescript2": "^0.36.0",
|
|
87
87
|
"start-server-and-test": "^2.0",
|
|
88
|
-
"ts-jest": "^29.0
|
|
89
|
-
"tslib": "^2.
|
|
90
|
-
"typedoc": "^0.
|
|
91
|
-
"typescript": "^
|
|
88
|
+
"ts-jest": "^29.4.0",
|
|
89
|
+
"tslib": "^2.8.1",
|
|
90
|
+
"typedoc": "^0.28.7",
|
|
91
|
+
"typescript": "^5.8.3"
|
|
92
92
|
},
|
|
93
93
|
"peerDependencies": {
|
|
94
94
|
"react": "^16.11.0 || ^17 || ^18 || ^19",
|
|
95
95
|
"react-dom": "^16.11.0 || ^17 || ^18 || ^19"
|
|
96
96
|
},
|
|
97
97
|
"dependencies": {
|
|
98
|
-
"@auth0/auth0-spa-js": "^2.
|
|
98
|
+
"@auth0/auth0-spa-js": "^2.2.0"
|
|
99
99
|
}
|
|
100
100
|
}
|
package/src/auth-state.tsx
CHANGED
|
@@ -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
|
|
7
|
+
error: Error | undefined;
|
|
8
8
|
isAuthenticated: boolean;
|
|
9
9
|
isLoading: boolean;
|
|
10
|
-
user
|
|
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
|
};
|
package/src/auth0-context.tsx
CHANGED
|
@@ -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-
|
|
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-
|
|
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
|
|
package/src/auth0-provider.tsx
CHANGED
|
@@ -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?:
|
|
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
|
|
119
|
+
appState?.returnTo ?? window.location.pathname
|
|
120
120
|
);
|
|
121
121
|
};
|
|
122
122
|
|
|
@@ -132,7 +132,7 @@ const defaultOnRedirectCallback = (appState?: AppState): void => {
|
|
|
132
132
|
*
|
|
133
133
|
* Provides the Auth0Context to its child components.
|
|
134
134
|
*/
|
|
135
|
-
const Auth0Provider = (opts: Auth0ProviderOptions) => {
|
|
135
|
+
const Auth0Provider = <TUser extends User = User>(opts: Auth0ProviderOptions<TUser>) => {
|
|
136
136
|
const {
|
|
137
137
|
children,
|
|
138
138
|
skipRedirectCallback,
|
|
@@ -143,7 +143,7 @@ const Auth0Provider = (opts: Auth0ProviderOptions) => {
|
|
|
143
143
|
const [client] = useState(
|
|
144
144
|
() => new Auth0Client(toAuth0ClientOptions(clientOpts))
|
|
145
145
|
);
|
|
146
|
-
const [state, dispatch] = useReducer(reducer
|
|
146
|
+
const [state, dispatch] = useReducer(reducer<TUser>, initialAuthState as AuthState<TUser>);
|
|
147
147
|
const didInitialise = useRef(false);
|
|
148
148
|
|
|
149
149
|
const handleError = useCallback((error: Error) => {
|
|
@@ -158,7 +158,7 @@ const Auth0Provider = (opts: Auth0ProviderOptions) => {
|
|
|
158
158
|
didInitialise.current = true;
|
|
159
159
|
(async (): Promise<void> => {
|
|
160
160
|
try {
|
|
161
|
-
let user:
|
|
161
|
+
let user: TUser | undefined;
|
|
162
162
|
if (hasAuthParams() && !skipRedirectCallback) {
|
|
163
163
|
const { appState } = await client.handleRedirectCallback();
|
|
164
164
|
user = await client.getUser();
|
|
@@ -198,7 +198,7 @@ const Auth0Provider = (opts: Auth0ProviderOptions) => {
|
|
|
198
198
|
const user = await client.getUser();
|
|
199
199
|
dispatch({ type: 'LOGIN_POPUP_COMPLETE', user });
|
|
200
200
|
},
|
|
201
|
-
[client]
|
|
201
|
+
[client, handleError]
|
|
202
202
|
);
|
|
203
203
|
|
|
204
204
|
const logout = useCallback(
|
|
@@ -272,7 +272,7 @@ const Auth0Provider = (opts: Auth0ProviderOptions) => {
|
|
|
272
272
|
[client]
|
|
273
273
|
);
|
|
274
274
|
|
|
275
|
-
const contextValue = useMemo<Auth0ContextInterface<
|
|
275
|
+
const contextValue = useMemo<Auth0ContextInterface<TUser>>(() => {
|
|
276
276
|
return {
|
|
277
277
|
...state,
|
|
278
278
|
getAccessTokenSilently,
|
package/src/errors.tsx
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
export class OAuthError extends Error {
|
|
8
8
|
constructor(public error: string, public error_description?: string) {
|
|
9
|
-
super(error_description
|
|
9
|
+
super(error_description ?? error);
|
|
10
10
|
|
|
11
11
|
// https://github.com/Microsoft/TypeScript-wiki/blob/master/Breaking-Changes.md#extending-built-ins-like-error-array-and-map-may-no-longer-work
|
|
12
12
|
Object.setPrototypeOf(this, OAuthError.prototype);
|
package/src/reducer.tsx
CHANGED
|
@@ -9,7 +9,7 @@ type Action =
|
|
|
9
9
|
| 'LOGIN_POPUP_COMPLETE'
|
|
10
10
|
| 'GET_ACCESS_TOKEN_COMPLETE'
|
|
11
11
|
| 'HANDLE_REDIRECT_COMPLETE';
|
|
12
|
-
user
|
|
12
|
+
user: User | undefined;
|
|
13
13
|
}
|
|
14
14
|
| { type: 'LOGOUT' }
|
|
15
15
|
| { type: 'ERROR'; error: Error };
|
|
@@ -17,7 +17,7 @@ type Action =
|
|
|
17
17
|
/**
|
|
18
18
|
* Handles how that state changes in the `useAuth0` hook.
|
|
19
19
|
*/
|
|
20
|
-
export const reducer = (state: AuthState
|
|
20
|
+
export const reducer = <TUser extends User = User>(state: AuthState<TUser>, action: Action): AuthState<TUser> => {
|
|
21
21
|
switch (action.type) {
|
|
22
22
|
case 'LOGIN_POPUP_STARTED':
|
|
23
23
|
return {
|
|
@@ -29,7 +29,7 @@ export const reducer = (state: AuthState, action: Action): AuthState => {
|
|
|
29
29
|
return {
|
|
30
30
|
...state,
|
|
31
31
|
isAuthenticated: !!action.user,
|
|
32
|
-
user: action.user,
|
|
32
|
+
user: action.user as TUser | undefined,
|
|
33
33
|
isLoading: false,
|
|
34
34
|
error: undefined,
|
|
35
35
|
};
|
|
@@ -41,7 +41,7 @@ export const reducer = (state: AuthState, action: Action): AuthState => {
|
|
|
41
41
|
return {
|
|
42
42
|
...state,
|
|
43
43
|
isAuthenticated: !!action.user,
|
|
44
|
-
user: action.user,
|
|
44
|
+
user: action.user as TUser | undefined,
|
|
45
45
|
};
|
|
46
46
|
case 'LOGOUT':
|
|
47
47
|
return {
|