express-sweet 1.0.34 → 1.0.35

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/docs/index.html CHANGED
@@ -81,7 +81,7 @@
81
81
  <!--begin::Title-->
82
82
  <h1 class="page-heading d-flex text-dark fw-bold fs-3 justify-content-center align-items-baseline my-0">
83
83
  <!-- <h1 class="page-heading d-flex text-dark fw-bold fs-3 flex-column justify-content-center my-0"> -->
84
- DevDocs<a href="#changelog" class="badge fw-semibold fs-7 px-2 ms-2 bg-body text-dark text-hover-primary shadow-sm">v1.0.34</a>
84
+ DevDocs<a href="#changelog" class="badge fw-semibold fs-7 px-2 ms-2 bg-body text-dark text-hover-primary shadow-sm">v1.0.35</a>
85
85
  </h1>
86
86
  <!--end::Title-->
87
87
  </div>
@@ -5753,11 +5753,30 @@ await BookModel.query(&quot;SELECT * FROM book&quot;, {type: BookModel.QueryType
5753
5753
  </td>
5754
5754
  </tr>
5755
5755
  <tr>
5756
- <td class="w-250px"><code>failure_redirect: string</code></td>
5756
+ <td class="w-250px"><code>failure_redirect: string|((req: express.Request, res: express.Response) =&gt; string)</code></td>
5757
5757
  <td>
5758
5758
  Specify the URL to redirect after logging out, or the URL to redirect when the logoff user requests a URL that only the logged-in user can access.<br>
5759
5759
  This usually specifies the URL of the login page.<br>
5760
5760
  The default is <code>/login</code>.
5761
+ <!--begin::Code-->
5762
+ <div class="py-5">
5763
+ <!--begin::Highlight-->
5764
+ <div class="highlight">
5765
+ <button class="highlight-copy btn" data-bs-toggle="tooltip" title="Copy code">copy</button>
5766
+ <div class="highlight-code">
5767
+ <pre class="language-javascript"><code class="language-javascript">// Set the URL to redirect to in case of login failure as a string.
5768
+ failure_redirect: &#039;/login&#039;,
5769
+
5770
+ // Dynamically set the url to redirect to on login failure.
5771
+ failure_redirect: (req, res) =&gt; {
5772
+ // If the role stored in the cookie is admin, redirect to the admin login screen.
5773
+ return req.cookies.role === &#039;admin&#039; ? &#039;/adminlogin&#039; : &#039;login&#039;;
5774
+ },</code></pre>
5775
+ </div>
5776
+ </div>
5777
+ <!--end::Highlight-->
5778
+ </div>
5779
+ <!--end::Code-->
5761
5780
  </td>
5762
5781
  </tr>
5763
5782
  <tr>
@@ -6007,7 +6026,7 @@ router.post(&#039;/login&#039;, async (req, res, next) =&gt; {
6007
6026
  if (isAuth)
6008
6027
  Authentication.successRedirect(res);
6009
6028
  else
6010
- Authentication.failureRedirect(res);
6029
+ Authentication.failureRedirect(req, res);
6011
6030
  });
6012
6031
  export default router;</code></pre>
6013
6032
  </div>
@@ -6023,7 +6042,7 @@ router.post(&#039;/login&#039;, async (req, res, next) =&gt; {
6023
6042
  if (isAuth)
6024
6043
  Authentication.successRedirect(res);
6025
6044
  else
6026
- Authentication.failureRedirect(res);
6045
+ Authentication.failureRedirect(req, res);
6027
6046
  });
6028
6047
  module.exports = router;</code></pre>
6029
6048
  </div>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "express-sweet",
3
- "version": "1.0.34",
3
+ "version": "1.0.35",
4
4
  "description": "Express framework extension.",
5
5
  "main": "dist/build.common.js",
6
6
  "module": "dist/build.esm.js",
@@ -38,9 +38,20 @@ export default interface {
38
38
  success_redirect: string;
39
39
  /**
40
40
  * URL to redirect after log off, defaults to `/login`.
41
- * @type {string}
41
+ *
42
+ * @example
43
+ * // Set the URL to redirect to in case of login failure as a string.
44
+ * failure_redirect: '/login',
45
+ *
46
+ * // Dynamically set the url to redirect to on login failure.
47
+ * failure_redirect: (req, res) => {
48
+ * // If the role stored in the cookie is admin, redirect to the admin login screen.
49
+ * return req.cookies.role === 'admin' ? '/adminlogin' : 'login';
50
+ * },
51
+ *
52
+ * @type {string|((req: express.Request, res: express.Response) => string)}
42
53
  */
43
- failure_redirect: string;
54
+ failure_redirect: string | ((req: express.Request, res: express.Response) => string);
44
55
  /**
45
56
  * This hook is called when authenticating a user.
46
57
  * Please find the user information that owns the credentials based on the user name and password you received and return it.
@@ -28,7 +28,8 @@ export default class {
28
28
  /**
29
29
  * Redirects to the page that responds immediately after authentication failure set in "failure_redirect" of "config/authentication.js".
30
30
  *
31
+ * @param {express.Request} req The req object represents the HTTP request and has properties for the request query string, parameters, body, HTTP headers, and so on.
31
32
  * @param {express.Response} res The res object represents the HTTP response that an Express app sends when it gets an HTTP request.
32
33
  */
33
- static failureRedirect(res: express.Response): void;
34
+ static failureRedirect(req: express.Request, res: express.Response): void;
34
35
  }
@@ -1,7 +1,8 @@
1
1
  declare const _default: {
2
- isAsyncFunction: (value: Function) => boolean;
3
- isString: (value: any) => boolean;
4
- isObject: (value: any) => boolean;
5
2
  isArray: (value: any) => boolean;
3
+ isAsyncFunction: (value: any) => boolean;
4
+ isFunction: (value: any) => boolean;
5
+ isObject: (value: any) => boolean;
6
+ isString: (value: any) => boolean;
6
7
  };
7
8
  export default _default;
@@ -1,12 +1,12 @@
1
1
  /**
2
- * Returns true for asynchronous functions, false otherwise.
3
- *
4
- * @example
5
- * utils.isAsyncFunction(async () => {});// true
6
- * utils.isAsyncFunction(() => {});// false
7
- *
8
- * @param {Function} value
9
- * @return {boolean}
10
- */
11
- declare const _default: (value: Function) => boolean;
2
+ * Returns true for asynchronous functions, false otherwise.
3
+ *
4
+ * @example
5
+ * utils.isAsyncFunction(async () => {});// true
6
+ * utils.isAsyncFunction(() => {});// false
7
+ *
8
+ * @param {any} value
9
+ * @return {boolean}
10
+ */
11
+ declare const _default: (value: any) => boolean;
12
12
  export default _default;
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Returns true for functions, false otherwise.
3
+ *
4
+ * @example
5
+ * utils.isFunction(() => {});// true
6
+ * utils.isFunction(async () => {});// true
7
+ * utils.isFunction('');// false
8
+ *
9
+ * @param {any} value
10
+ * @return {boolean}
11
+ */
12
+ declare const _default: (value: any) => boolean;
13
+ export default _default;