@auth0/auth0-react 1.4.0 → 1.8.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/README.md CHANGED
@@ -103,6 +103,14 @@ function App() {
103
103
  export default App;
104
104
  ```
105
105
 
106
+ If you're using TypeScript, you can pass a type parameter to `useAuth0` to specify the type of `user`:
107
+
108
+ ```ts
109
+ const { user } = useAuth0<{ name: string }>();
110
+
111
+ user.name; // is a string
112
+ ```
113
+
106
114
  ### Use with a Class Component
107
115
 
108
116
  Use the `withAuth0` higher order component to add the `auth0` property to Class components:
@@ -195,7 +203,7 @@ We appreciate feedback and contribution to this repo! Before you get started, pl
195
203
 
196
204
  - [Auth0's general contribution guidelines](https://github.com/auth0/open-source-template/blob/master/GENERAL-CONTRIBUTING.md)
197
205
  - [Auth0's code of conduct guidelines](https://github.com/auth0/open-source-template/blob/master/CODE-OF-CONDUCT.md)
198
- - [This repo's contribution guide](./CONTRIBUTING.md)
206
+ - [This repo's contribution guide](https://github.com/auth0/auth0-react/blob/master/CONTRIBUTING.md)
199
207
 
200
208
  ## Support + Feedback
201
209
 
@@ -203,11 +211,11 @@ For support or to provide feedback, please [raise an issue on our issue tracker]
203
211
 
204
212
  ## Troubleshooting
205
213
 
206
- For information on how to solve common problems, check out the [Troubleshooting](./TROUBLESHOOTING.md) guide
214
+ For information on how to solve common problems, check out the [Troubleshooting](https://github.com/auth0/auth0-react/blob/master/TROUBLESHOOTING.md) guide
207
215
 
208
216
  ## Frequently Asked Questions
209
217
 
210
- For a rundown of common issues you might encounter when using the SDK, please check out the [FAQ](./FAQ.md).
218
+ For a rundown of common issues you might encounter when using the SDK, please check out the [FAQ](https://github.com/auth0/auth0-react/blob/master/FAQ.md).
211
219
 
212
220
  ## Vulnerability Reporting
213
221
 
@@ -1,12 +1,12 @@
1
- export declare type User = any;
1
+ import { User } from '@auth0/auth0-spa-js';
2
2
  /**
3
3
  * The auth state which, when combined with the auth methods, make up the return object of the `useAuth0` hook.
4
4
  */
5
- export interface AuthState {
5
+ export interface AuthState<TUser extends User = User> {
6
6
  error?: Error;
7
7
  isAuthenticated: boolean;
8
8
  isLoading: boolean;
9
- user?: User;
9
+ user?: TUser;
10
10
  }
11
11
  /**
12
12
  * The initial auth state.
@@ -1 +1 @@
1
- {"version":3,"file":"auth-state.d.ts","sourceRoot":"","sources":["../src/auth-state.tsx"],"names":[],"mappings":"AAAA,oBAAY,IAAI,GAAG,GAAG,CAAC;AAEvB;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,KAAK,CAAC,EAAE,KAAK,CAAC;IACd,eAAe,EAAE,OAAO,CAAC;IACzB,SAAS,EAAE,OAAO,CAAC;IACnB,IAAI,CAAC,EAAE,IAAI,CAAC;CACb;AAED;;GAEG;AACH,eAAO,MAAM,gBAAgB,EAAE,SAG9B,CAAC"}
1
+ {"version":3,"file":"auth-state.d.ts","sourceRoot":"","sources":["../src/auth-state.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAE3C;;GAEG;AACH,MAAM,WAAW,SAAS,CAAC,KAAK,SAAS,IAAI,GAAG,IAAI;IAClD,KAAK,CAAC,EAAE,KAAK,CAAC;IACd,eAAe,EAAE,OAAO,CAAC;IACzB,SAAS,EAAE,OAAO,CAAC;IACnB,IAAI,CAAC,EAAE,KAAK,CAAC;CACd;AAED;;GAEG;AACH,eAAO,MAAM,gBAAgB,EAAE,SAG9B,CAAC"}
@@ -1,5 +1,5 @@
1
1
  /// <reference types="react" />
2
- import { BaseLoginOptions, GetIdTokenClaimsOptions, GetTokenSilentlyOptions, GetTokenWithPopupOptions, IdToken, LogoutOptions, LogoutUrlOptions, PopupLoginOptions, PopupConfigOptions, RedirectLoginOptions as Auth0RedirectLoginOptions } from '@auth0/auth0-spa-js';
2
+ import { BaseLoginOptions, GetIdTokenClaimsOptions, GetTokenSilentlyOptions, GetTokenWithPopupOptions, IdToken, LogoutOptions, LogoutUrlOptions, PopupLoginOptions, PopupConfigOptions, RedirectLoginOptions as Auth0RedirectLoginOptions, RedirectLoginResult, User } from '@auth0/auth0-spa-js';
3
3
  import { AuthState } from './auth-state';
4
4
  export interface RedirectLoginOptions extends BaseLoginOptions {
5
5
  /**
@@ -21,7 +21,7 @@ export interface RedirectLoginOptions extends BaseLoginOptions {
21
21
  /**
22
22
  * Contains the authenticated state and authentication methods provided by the `useAuth0` hook.
23
23
  */
24
- export interface Auth0ContextInterface extends AuthState {
24
+ export interface Auth0ContextInterface<TUser extends User = User> extends AuthState<TUser> {
25
25
  /**
26
26
  * ```js
27
27
  * const token = await getAccessTokenSilently(options);
@@ -126,10 +126,19 @@ export interface Auth0ContextInterface extends AuthState {
126
126
  * @param options
127
127
  */
128
128
  buildLogoutUrl: (options?: LogoutUrlOptions) => string;
129
+ /**
130
+ * After the browser redirects back to the callback page,
131
+ * call `handleRedirectCallback` to handle success and error
132
+ * responses from Auth0. If the response is successful, results
133
+ * will be valid according to their expiration times.
134
+ *
135
+ * @param url The URL to that should be used to retrieve the `state` and `code` values. Defaults to `window.location.href` if not given.
136
+ */
137
+ handleRedirectCallback: (url?: string) => Promise<RedirectLoginResult>;
129
138
  }
130
139
  /**
131
140
  * The Auth0 Context
132
141
  */
133
- declare const Auth0Context: import("react").Context<Auth0ContextInterface>;
142
+ declare const Auth0Context: import("react").Context<Auth0ContextInterface<User>>;
134
143
  export default Auth0Context;
135
144
  //# sourceMappingURL=auth0-context.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"auth0-context.d.ts","sourceRoot":"","sources":["../src/auth0-context.tsx"],"names":[],"mappings":";AAAA,OAAO,EACL,gBAAgB,EAChB,uBAAuB,EACvB,uBAAuB,EACvB,wBAAwB,EACxB,OAAO,EACP,aAAa,EACb,gBAAgB,EAChB,iBAAiB,EACjB,kBAAkB,EAClB,oBAAoB,IAAI,yBAAyB,EAClD,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAE,SAAS,EAAoB,M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,OAAO,CAAC,EAAE,iBAAiB,EAC3B,MAAM,CAAC,EAAE,kBAAkB,KACxB,OAAO,CAAC,IAAI,CAAC,CAAC;IAEnB;;;;;;;;;;;;OAYG;IACH,MAAM,EAAE,CAAC,OAAO,CAAC,EAAE,aAAa,KAAK,IAAI,CAAC;IAE1C;;;;;;;;OAQG;IACH,iBAAiB,EAAE,CAAC,OAAO,CAAC,EAAE,yBAAyB,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;IAE5E;;;;;;;OAOG;IACH,cAAc,EAAE,CAAC,OAAO,CAAC,EAAE,gBAAgB,KAAK,MAAM,CAAC;IAEvD;;;;;;;OAOG;IACH,sBAAsB,EAAE,CAAC,GAAG,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC,mBAAmB,CAAC,CAAC;CACxE;AAyBD;;GAEG;AACH,QAAA,MAAM,YAAY,sDAAuD,CAAC;AAE1E,eAAe,YAAY,CAAC"}
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { CacheLocation } from '@auth0/auth0-spa-js';
2
+ import { CacheLocation, ICache } from '@auth0/auth0-spa-js';
3
3
  /**
4
4
  * The state of the application before the user was redirected to the login page.
5
5
  */
@@ -70,6 +70,12 @@ export interface Auth0ProviderOptions {
70
70
  * Read more about [changing storage options in the Auth0 docs](https://auth0.com/docs/libraries/auth0-single-page-app-sdk#change-storage-options)
71
71
  */
72
72
  cacheLocation?: CacheLocation;
73
+ /**
74
+ * Specify a custom cache implementation to use for token storage and retrieval. This setting takes precedence over `cacheLocation` if they are both specified.
75
+ *
76
+ * Read more about [creating a custom cache](https://github.com/auth0/auth0-spa-js#creating-a-custom-cache)
77
+ */
78
+ cache?: ICache;
73
79
  /**
74
80
  * If true, refresh tokens are used to fetch new access tokens from the Auth0 server. If false, the legacy technique of using a hidden iframe and the `authorization_code` grant with `prompt=none` is used.
75
81
  * The default setting is `false`.
@@ -111,7 +117,7 @@ export interface Auth0ProviderOptions {
111
117
  */
112
118
  audience?: string;
113
119
  /**
114
- * The Id of an organization to log in to (Organizations is currently a Closed Beta).
120
+ * The Id of an organization to log in to.
115
121
  *
116
122
  * This will specify an `organization` parameter in your user's login request and will add a step to validate
117
123
  * the `org_id` claim in your user's ID Token.
@@ -1 +1 @@
1
- {"version":3,"file":"auth0-provider.d.ts","sourceRoot":"","sources":["../src/auth0-provider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAuD,MAAM,OAAO,CAAC;AAC5E,OAAO,EAGL,aAAa,EAUd,MAAM,qBAAqB,CAAC;AAM7B;;GAEG;AACH,oBAAY,QAAQ,GAAG;IACrB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB,CAAC;AAEF;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC;;OAEG;IACH,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC3B;;;;OAIG;IACH,kBAAkB,CAAC,EAAE,CAAC,QAAQ,EAAE,QAAQ,KAAK,IAAI,CAAC;IAClD;;;;;;;;;;;;OAYG;IACH,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B;;;;OAIG;IACH,MAAM,EAAE,MAAM,CAAC;IACf;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;IACjB;;;;;;OAMG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;;OAIG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;;;OAKG;IACH,aAAa,CAAC,EAAE,aAAa,CAAC;IAC9B;;;;;OAKG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B;;;OAGG;IACH,yBAAyB,CAAC,EAAE,MAAM,CAAC;IACnC;;OAEG;IACH,eAAe,CAAC,EAAE;QAChB;;;;;WAKG;QACH,YAAY,CAAC,EAAE,MAAM,CAAC;KACvB,CAAC;IACF;;;;OAIG;IACH,MAA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