@auth0/auth0-react 2.0.2 → 2.1.1

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.
@@ -32,6 +32,16 @@ export interface WithAuthenticationRequiredOptions {
32
32
  * Render a message to show that the user is being redirected to the login.
33
33
  */
34
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>;
35
45
  /**
36
46
  * ```js
37
47
  * withAuthenticationRequired(Profile, {
@@ -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;AAazB;;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;;;;;;;;;;;;;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,gBAqC3C,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,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"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "author": "Auth0",
3
3
  "name": "@auth0/auth0-react",
4
- "version": "2.0.2",
4
+ "version": "2.1.1",
5
5
  "description": "Auth0 SDK for React Single Page Applications (SPA)",
6
6
  "keywords": [
7
7
  "auth0",
@@ -96,6 +96,6 @@
96
96
  "react-dom": "^16.11.0 || ^17 || ^18"
97
97
  },
98
98
  "dependencies": {
99
- "@auth0/auth0-spa-js": "^2.0.4"
99
+ "@auth0/auth0-spa-js": "^2.0.8"
100
100
  }
101
101
  }
@@ -10,6 +10,11 @@ import Auth0Context, {
10
10
  */
11
11
  const defaultOnRedirecting = (): JSX.Element => <></>;
12
12
 
13
+ /**
14
+ * @ignore
15
+ */
16
+ const defaultOnBeforeAuthentication = async (): Promise<void> => {/* noop */};
17
+
13
18
  /**
14
19
  * @ignore
15
20
  */
@@ -48,6 +53,16 @@ export interface WithAuthenticationRequiredOptions {
48
53
  * Render a message to show that the user is being redirected to the login.
49
54
  */
50
55
  onRedirecting?: () => JSX.Element;
56
+ /**
57
+ * ```js
58
+ * withAuthenticationRequired(Profile, {
59
+ * onBeforeAuthentication: () => { analyticsLibrary.track('login_triggered'); }
60
+ * })
61
+ * ```
62
+ *
63
+ * Allows executing logic before the user is redirected to the login page.
64
+ */
65
+ onBeforeAuthentication?: () => Promise<void>;
51
66
  /**
52
67
  * ```js
53
68
  * withAuthenticationRequired(Profile, {
@@ -87,6 +102,7 @@ const withAuthenticationRequired = <P extends object>(
87
102
  const {
88
103
  returnTo = defaultReturnTo,
89
104
  onRedirecting = defaultOnRedirecting,
105
+ onBeforeAuthentication = defaultOnBeforeAuthentication,
90
106
  loginOptions,
91
107
  context = Auth0Context,
92
108
  } = options;
@@ -106,12 +122,14 @@ const withAuthenticationRequired = <P extends object>(
106
122
  },
107
123
  };
108
124
  (async (): Promise<void> => {
125
+ await onBeforeAuthentication();
109
126
  await loginWithRedirect(opts);
110
127
  })();
111
128
  }, [
112
129
  isLoading,
113
130
  isAuthenticated,
114
131
  loginWithRedirect,
132
+ onBeforeAuthentication,
115
133
  loginOptions,
116
134
  returnTo,
117
135
  ]);