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/CHANGELOG.md
CHANGED
|
@@ -1,7 +1,47 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
All notable changes to this project will be documented in this file.
|
|
3
3
|
|
|
4
|
+
## [1.0.35] - 2023/7/11
|
|
5
|
+
### Changed
|
|
6
|
+
- The URL to redirect to when login fails (failure_redirect) option in the authentication configuration (config/authentication.js) can now be defined with a function.
|
|
7
|
+
|
|
8
|
+
config/authentication.js:
|
|
9
|
+
```js
|
|
10
|
+
// Set the URL to redirect to in case of login failure as a string.
|
|
11
|
+
failure_redirect: '/login',
|
|
12
|
+
|
|
13
|
+
// Dynamically set the url to redirect to on login failure.
|
|
14
|
+
failure_redirect: (req, res) => {
|
|
15
|
+
// If the role stored in the cookie is admin, redirect to the admin login screen.
|
|
16
|
+
return req.cookies.role === 'admin' ? '/adminlogin' : 'login';
|
|
17
|
+
},
|
|
18
|
+
```
|
|
19
|
+
- The arguments of the failureRedirect method of the authentication service class (services/Authentication) have changed.
|
|
20
|
+
The argument to the Authentication.failureRedirect method used to be just express.Response, but now it requires express.Request and express.Response.
|
|
21
|
+
|
|
22
|
+
Example of login routes:
|
|
23
|
+
```js
|
|
24
|
+
import {Router} from 'express';
|
|
25
|
+
import * as sweet from 'express-sweet';
|
|
26
|
+
const router = Router();
|
|
27
|
+
const Authentication = sweet.services.Authentication;
|
|
28
|
+
|
|
29
|
+
router.post('/login', async (req, res, next) => {
|
|
30
|
+
const isAuth = await Authentication.authenticate(req, res, next);
|
|
31
|
+
if (isAuth)
|
|
32
|
+
Authentication.successRedirect(res);
|
|
33
|
+
else
|
|
34
|
+
Authentication.failureRedirect(req, res);
|
|
35
|
+
});
|
|
36
|
+
export default router;
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## [1.0.34] - 2023/7/1
|
|
40
|
+
### Changed
|
|
41
|
+
- Changed the response status code from 403 to 401 when asynchronous communication requiring authentication fails to authenticate.
|
|
42
|
+
|
|
4
43
|
## [1.0.33] - 2023/7/1
|
|
44
|
+
### Added
|
|
5
45
|
- Added regular expression comparison view helper.
|
|
6
46
|
```html
|
|
7
47
|
{{!-- results in: true --}}
|
|
@@ -584,4 +624,6 @@ All notable changes to this project will be documented in this file.
|
|
|
584
624
|
[1.0.30]: https://github.com/takuya-motoshima/express-sweet/compare/v1.0.29...v1.0.30
|
|
585
625
|
[1.0.31]: https://github.com/takuya-motoshima/express-sweet/compare/v1.0.30...v1.0.31
|
|
586
626
|
[1.0.32]: https://github.com/takuya-motoshima/express-sweet/compare/v1.0.31...v1.0.32
|
|
587
|
-
[1.0.33]: https://github.com/takuya-motoshima/express-sweet/compare/v1.0.32...v1.0.33
|
|
627
|
+
[1.0.33]: https://github.com/takuya-motoshima/express-sweet/compare/v1.0.32...v1.0.33
|
|
628
|
+
[1.0.34]: https://github.com/takuya-motoshima/express-sweet/compare/v1.0.33...v1.0.34
|
|
629
|
+
[1.0.35]: https://github.com/takuya-motoshima/express-sweet/compare/v1.0.34...v1.0.35
|