@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/auth-state.d.ts +14 -14
- package/dist/auth-state.d.ts.map +1 -1
- package/dist/auth0-context.d.ts +134 -133
- 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 +456 -435
- package/dist/auth0-react.cjs.js.map +1 -1
- package/dist/auth0-react.esm.js +455 -434
- package/dist/auth0-react.esm.js.map +1 -1
- package/dist/auth0-react.js +456 -435
- 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 +20 -21
- package/src/auth-state.tsx +4 -2
- package/src/auth0-context.tsx +5 -3
- package/src/auth0-provider.tsx +19 -14
- package/src/errors.tsx +1 -1
- package/src/reducer.tsx +4 -4
- package/src/utils.tsx +1 -1
- package/src/with-auth0.tsx +2 -2
- package/src/with-authentication-required.tsx +6 -6
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 {
|
package/src/utils.tsx
CHANGED
|
@@ -47,7 +47,7 @@ export const deprecateRedirectUri = (options?: any) => {
|
|
|
47
47
|
console.warn(
|
|
48
48
|
'Using `redirectUri` has been deprecated, please use `authorizationParams.redirect_uri` instead as `redirectUri` will be no longer supported in a future version'
|
|
49
49
|
);
|
|
50
|
-
options.authorizationParams = options.authorizationParams
|
|
50
|
+
options.authorizationParams = options.authorizationParams ?? {};
|
|
51
51
|
options.authorizationParams.redirect_uri = options.redirectUri;
|
|
52
52
|
delete options.redirectUri;
|
|
53
53
|
}
|
package/src/with-auth0.tsx
CHANGED
|
@@ -30,10 +30,10 @@ const withAuth0 = <P extends WithAuth0Props>(
|
|
|
30
30
|
Component: ComponentType<P>,
|
|
31
31
|
context = Auth0Context
|
|
32
32
|
): ComponentType<Omit<P, keyof WithAuth0Props>> => {
|
|
33
|
-
return function WithAuth(props): JSX.Element {
|
|
33
|
+
return function WithAuth(props): React.JSX.Element {
|
|
34
34
|
return (
|
|
35
35
|
<context.Consumer>
|
|
36
|
-
{(auth: Auth0ContextInterface): JSX.Element => (
|
|
36
|
+
{(auth: Auth0ContextInterface): React.JSX.Element => (
|
|
37
37
|
<Component {...(props as P)} auth0={auth} />
|
|
38
38
|
)}
|
|
39
39
|
</context.Consumer>
|
|
@@ -8,12 +8,12 @@ import Auth0Context, {
|
|
|
8
8
|
/**
|
|
9
9
|
* @ignore
|
|
10
10
|
*/
|
|
11
|
-
const defaultOnRedirecting = (): JSX.Element => <></>;
|
|
11
|
+
const defaultOnRedirecting = (): React.JSX.Element => <></>;
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* @ignore
|
|
15
15
|
*/
|
|
16
|
-
const defaultOnBeforeAuthentication = async (): Promise<void> => {/* noop */};
|
|
16
|
+
const defaultOnBeforeAuthentication = async (): Promise<void> => {/* noop */ };
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
19
|
* @ignore
|
|
@@ -52,7 +52,7 @@ export interface WithAuthenticationRequiredOptions {
|
|
|
52
52
|
*
|
|
53
53
|
* Render a message to show that the user is being redirected to the login.
|
|
54
54
|
*/
|
|
55
|
-
onRedirecting?: () => JSX.Element;
|
|
55
|
+
onRedirecting?: () => React.JSX.Element;
|
|
56
56
|
/**
|
|
57
57
|
* ```js
|
|
58
58
|
* withAuthenticationRequired(Profile, {
|
|
@@ -98,7 +98,7 @@ const withAuthenticationRequired = <P extends object>(
|
|
|
98
98
|
Component: ComponentType<P>,
|
|
99
99
|
options: WithAuthenticationRequiredOptions = {}
|
|
100
100
|
): FC<P> => {
|
|
101
|
-
return function WithAuthenticationRequired(props: P): JSX.Element {
|
|
101
|
+
return function WithAuthenticationRequired(props: P): React.JSX.Element {
|
|
102
102
|
const {
|
|
103
103
|
returnTo = defaultReturnTo,
|
|
104
104
|
onRedirecting = defaultOnRedirecting,
|
|
@@ -117,11 +117,11 @@ const withAuthenticationRequired = <P extends object>(
|
|
|
117
117
|
const opts = {
|
|
118
118
|
...loginOptions,
|
|
119
119
|
appState: {
|
|
120
|
-
...
|
|
120
|
+
...loginOptions?.appState,
|
|
121
121
|
returnTo: typeof returnTo === 'function' ? returnTo() : returnTo,
|
|
122
122
|
},
|
|
123
123
|
};
|
|
124
|
-
(async (): Promise<void> => {
|
|
124
|
+
void (async (): Promise<void> => {
|
|
125
125
|
await onBeforeAuthentication();
|
|
126
126
|
await loginWithRedirect(opts);
|
|
127
127
|
})();
|