express-sweet-generator 1.0.9 → 1.0.10

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 CHANGED
@@ -1,6 +1,41 @@
1
1
  # Changelog
2
2
  All notable changes to this project will be documented in this file.
3
3
 
4
+ ## [1.0.10] - 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
+
4
39
  ## [1.0.9] - 2023/6/29
5
40
  ### Changed
6
41
  - Changed helper function names in the view (Handlebars) from SnakeCase to CamelCase.
@@ -161,4 +196,5 @@ All notable changes to this project will be documented in this file.
161
196
  [1.0.6]: https://github.com/takuya-motoshima/express-sweet-generator/compare/v1.0.5...v1.0.6
162
197
  [1.0.7]: https://github.com/takuya-motoshima/express-sweet-generator/compare/v1.0.6...v1.0.7
163
198
  [1.0.8]: https://github.com/takuya-motoshima/express-sweet-generator/compare/v1.0.7...v1.0.8
164
- [1.0.9]: https://github.com/takuya-motoshima/express-sweet-generator/compare/v1.0.8...v1.0.9
199
+ [1.0.9]: https://github.com/takuya-motoshima/express-sweet-generator/compare/v1.0.8...v1.0.9
200
+ [1.0.10]: https://github.com/takuya-motoshima/express-sweet-generator/compare/v1.0.9...v1.0.10
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "express-sweet-generator",
3
- "version": "1.0.9",
3
+ "version": "1.0.10",
4
4
  "description": "Express Sweet application generator.",
5
5
  "main": "bin/express-sweet-cli.js",
6
6
  "files": [
@@ -45,7 +45,18 @@ module.exports = {
45
45
 
46
46
  /**
47
47
  * URL to redirect after log off, defaults to `/login`.
48
- * @type {string}
48
+ *
49
+ * @example
50
+ * // Set the URL to redirect to in case of login failure as a string.
51
+ * failure_redirect: '/login',
52
+ *
53
+ * // Dynamically set the url to redirect to on login failure.
54
+ * failure_redirect: (req, res) => {
55
+ * // If the role stored in the cookie is admin, redirect to the admin login screen.
56
+ * return req.cookies.role === 'admin' ? '/adminlogin' : 'login';
57
+ * },
58
+ *
59
+ * @type {string|((req: express.Request, res: express.Response) => string)}
49
60
  */
50
61
  failure_redirect: '/login',
51
62
 
@@ -64,7 +64,7 @@
64
64
  <!--begin::User menu-->
65
65
  <div class="app-navbar-item ms-1 ms-lg-3" id="kt_header_user_menu_toggle">
66
66
  <!--begin::Menu wrapper-->
67
- <div class="cursor-pointer symbol symbol-35px symbol-md-40px" data-kt-menu-trigger="click" data-kt-menu-attach="parent" data-kt-menu-placement="bottom-end">
67
+ <div class="cursor-pointer symbol symbol-35px symbol-md-40px bg-dark" data-kt-menu-trigger="click" data-kt-menu-attach="parent" data-kt-menu-placement="bottom-end">
68
68
  <img src="{{session.icon}}?{{formatDate 'x' ''}}" alt="user" />
69
69
  {{!-- <img src="/build/theme/media/avatars/blank.png" alt="user" /> --}}
70
70
  </div>
@@ -45,7 +45,18 @@ export default {
45
45
 
46
46
  /**
47
47
  * URL to redirect after log off, defaults to `/login`.
48
- * @type {string}
48
+ *
49
+ * @example
50
+ * // Set the URL to redirect to in case of login failure as a string.
51
+ * failure_redirect: '/login',
52
+ *
53
+ * // Dynamically set the url to redirect to on login failure.
54
+ * failure_redirect: (req, res) => {
55
+ * // If the role stored in the cookie is admin, redirect to the admin login screen.
56
+ * return req.cookies.role === 'admin' ? '/adminlogin' : 'login';
57
+ * },
58
+ *
59
+ * @type {string|((req: express.Request, res: express.Response) => string)}
49
60
  */
50
61
  failure_redirect: '/login',
51
62
 
@@ -64,7 +64,7 @@
64
64
  <!--begin::User menu-->
65
65
  <div class="app-navbar-item ms-1 ms-lg-3" id="kt_header_user_menu_toggle">
66
66
  <!--begin::Menu wrapper-->
67
- <div class="cursor-pointer symbol symbol-35px symbol-md-40px" data-kt-menu-trigger="click" data-kt-menu-attach="parent" data-kt-menu-placement="bottom-end">
67
+ <div class="cursor-pointer symbol symbol-35px symbol-md-40px bg-dark" data-kt-menu-trigger="click" data-kt-menu-attach="parent" data-kt-menu-placement="bottom-end">
68
68
  <img src="{{session.icon}}?{{formatDate 'x' ''}}" alt="user" />
69
69
  {{!-- <img src="/build/theme/media/avatars/blank.png" alt="user" /> --}}
70
70
  </div>