express-generator-typescript 2.4.8 → 2.4.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.
@@ -130,3 +130,9 @@ function deleteUser(ele) {
130
130
  .delete('/api/users/delete/' + id)
131
131
  .then(() => displayUsers());
132
132
  }
133
+
134
+ function logoutUser() {
135
+ Http
136
+ .get('/api/auth/logout')
137
+ .then(() => window.location.href = '/');
138
+ }
@@ -32,6 +32,23 @@ function getSessionData<T>(req: Request): Promise<string | T | undefined> {
32
32
  return _decode(jwt);
33
33
  }
34
34
 
35
+ /**
36
+ * Decrypt JWT and extract client data.
37
+ */
38
+ function _decode<T>(jwt: string): Promise<string | undefined | T> {
39
+ return new Promise((res, rej) => {
40
+ jsonwebtoken.verify(jwt, EnvVars.Jwt.Secret, (err, decoded) => {
41
+ if (!!err) {
42
+ const err = new RouteError(HttpStatusCodes.UNAUTHORIZED,
43
+ Errors.Validation);
44
+ return rej(err);
45
+ } else {
46
+ return res(decoded as T);
47
+ }
48
+ });
49
+ });
50
+ }
51
+
35
52
  /**
36
53
  * Add a JWT to the response
37
54
  */
@@ -49,37 +66,23 @@ async function addSessionData(
49
66
  return res.cookie(Key, jwt, Options);
50
67
  }
51
68
 
52
- /**
53
- * Remove cookie
54
- */
55
- function clearCookie(res: Response): Response {
56
- const { Key, Options } = EnvVars.CookieProps;
57
- return res.clearCookie(Key, Options);
58
- }
59
-
60
-
61
- // **** Helper Functions **** //
62
-
63
69
  /**
64
70
  * Encrypt data and return jwt.
65
71
  */
66
72
  function _sign(data: string | object | Buffer): Promise<string> {
67
73
  return new Promise((res, rej) => {
68
74
  jsonwebtoken.sign(data, EnvVars.Jwt.Secret, Options, (err, token) => {
69
- return err ? rej(err) : res(token || '');
75
+ return (err ? rej(err) : res(token ?? ''));
70
76
  });
71
77
  });
72
78
  }
73
79
 
74
80
  /**
75
- * Decrypt JWT and extract client data.
81
+ * Remove cookie
76
82
  */
77
- function _decode<T>(jwt: string): Promise<string | undefined | T> {
78
- return new Promise((res, rej) => {
79
- jsonwebtoken.verify(jwt, EnvVars.Jwt.Secret, (err, decoded) => {
80
- return err ? rej(Errors.Validation) : res(decoded as T);
81
- });
82
- });
83
+ function clearCookie(res: Response): Response {
84
+ const { Key, Options } = EnvVars.CookieProps;
85
+ return res.clearCookie(Key, Options);
83
86
  }
84
87
 
85
88
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "express-generator-typescript",
3
- "version": "2.4.8",
3
+ "version": "2.4.10",
4
4
  "description": "Generate new Express applications similar to express-generate which but sets it up to use TypeScript instead",
5
5
  "scripts": {
6
6
  "express-generator-typescript": "node bin/cli.js",