express-sweet 1.0.33 → 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/CHANGELOG.md +43 -1
- package/dist/build.common.js +3 -3
- package/dist/build.esm.js +3 -3
- package/docs/index.html +24 -5
- package/package.json +1 -1
- package/types/interfaces/AuthenticationOptions.d.ts +13 -2
- package/types/middlewares/Authentication.d.ts +1 -1
- package/types/services/Authentication.d.ts +2 -1
- package/types/utils/index.d.ts +4 -3
- package/types/utils/isAsyncFunction.d.ts +10 -10
- package/types/utils/isFunction.d.ts +13 -0
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.
|
|
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>
|
|
@@ -5653,7 +5653,7 @@ await BookModel.query("SELECT * FROM book", {type: BookModel.QueryType
|
|
|
5653
5653
|
<!--begin::Description-->
|
|
5654
5654
|
<div class="text-gray-700 fw-bold fs-6">
|
|
5655
5655
|
If an unauthenticated user makes a request to a URL that allows access only if authenticated, the user will be redirected to the page specified by <code>failure_redirect</code>.<br>
|
|
5656
|
-
If that access is asynchronous, a <code>
|
|
5656
|
+
If that access is asynchronous, a <code>401</code> error is returned.
|
|
5657
5657
|
</div>
|
|
5658
5658
|
<!--end::Description-->
|
|
5659
5659
|
</div>
|
|
@@ -5753,11 +5753,30 @@ await BookModel.query("SELECT * FROM book", {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) => 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: '/login',
|
|
5769
|
+
|
|
5770
|
+
// Dynamically set the url to redirect to on login failure.
|
|
5771
|
+
failure_redirect: (req, res) => {
|
|
5772
|
+
// If the role stored in the cookie is admin, redirect to the admin login screen.
|
|
5773
|
+
return req.cookies.role === 'admin' ? '/adminlogin' : 'login';
|
|
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('/login', async (req, res, next) => {
|
|
|
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('/login', async (req, res, next) => {
|
|
|
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
|
@@ -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
|
-
*
|
|
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.
|
|
@@ -2,7 +2,7 @@ import express from 'express';
|
|
|
2
2
|
/**
|
|
3
3
|
* Incorporate user authentication into your application.
|
|
4
4
|
* If an unauthenticated user makes a request to a URL that allows access only if authenticated, the user will be redirected to the page specified by "failure_redirect".
|
|
5
|
-
* If that access is asynchronous, a
|
|
5
|
+
* If that access is asynchronous, a 401 error is returned.
|
|
6
6
|
*/
|
|
7
7
|
export default class {
|
|
8
8
|
#private;
|
|
@@ -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
|
}
|
package/types/utils/index.d.ts
CHANGED
|
@@ -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
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
declare const _default: (value:
|
|
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;
|