@nymphjs/tilmeld 1.0.0-beta.2 → 1.0.0-beta.20

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.
@@ -52,8 +52,9 @@ export default {
52
52
  maxUsernameLength: 128,
53
53
  jwtSecret: '',
54
54
  jwtExpire: 60 * 60 * 24 * 7 * 8, // 8 weeks(ish)
55
+ jwtSwitchExpire: 60 * 60 * 6, // 6 hours
55
56
  jwtRenew: 60 * 60 * 24 * 7 * 2, // 2 weeks(ish)
56
- jwtBuilder: (config, user) => {
57
+ jwtBuilder: (config, user, switchToken) => {
57
58
  const secret = config.jwtSecret;
58
59
  if (secret === '') {
59
60
  throw new Error('JWT secret is not configured.');
@@ -67,7 +68,7 @@ export default {
67
68
  xsrfToken: 'TILMELDXSRF-' + nanoid(),
68
69
  },
69
70
  secret,
70
- { expiresIn: config.jwtExpire }
71
+ { expiresIn: switchToken ? config.jwtSwitchExpire : config.jwtExpire }
71
72
  );
72
73
  },
73
74
  jwtExtract: (config, token, xsrfToken?) => {
@@ -86,7 +87,7 @@ export default {
86
87
  return null;
87
88
  }
88
89
 
89
- const { guid, xsrfToken: jwtXsrfToken, exp } = payload;
90
+ const { guid, xsrfToken: jwtXsrfToken, exp, nbf } = payload;
90
91
 
91
92
  if (xsrfToken != null && xsrfToken !== jwtXsrfToken) {
92
93
  return null;
@@ -96,13 +97,19 @@ export default {
96
97
  return null;
97
98
  }
98
99
 
100
+ if (nbf == null) {
101
+ return null;
102
+ }
103
+
104
+ const issued = new Date(nbf * 1000);
105
+
99
106
  if (exp == null) {
100
107
  return null;
101
108
  }
102
109
 
103
110
  const expire = new Date(exp * 1000);
104
111
 
105
- return { guid, expire };
112
+ return { guid, issued, expire };
106
113
  } catch (e: any) {
107
114
  return null;
108
115
  }
@@ -308,6 +315,7 @@ export default {
308
315
  recoverSecretDate: Joi.number(),
309
316
  salt: Joi.string().trim(false),
310
317
  password: Joi.string().trim(false).required(),
318
+ revokeTokenDate: Joi.number(),
311
319
  }),
312
320
  'Invalid User: '
313
321
  );
@@ -0,0 +1,20 @@
1
+ import { Entity, EntityConstructor, Nymph } from '@nymphjs/nymph';
2
+
3
+ import Tilmeld from './Tilmeld';
4
+
5
+ export function enforceTilmeld(object: Nymph | Entity | EntityConstructor) {
6
+ let tilmeld: Tilmeld | undefined;
7
+ if (object instanceof Entity) {
8
+ tilmeld = object.$nymph.tilmeld as Tilmeld | undefined;
9
+ } else if (object instanceof Nymph) {
10
+ tilmeld = object.tilmeld as Tilmeld | undefined;
11
+ } else {
12
+ tilmeld = object.nymph.tilmeld as Tilmeld | undefined;
13
+ }
14
+
15
+ if (tilmeld == null) {
16
+ throw new Error('Tilmeld was not configured on this Nymph instance!');
17
+ }
18
+
19
+ return tilmeld;
20
+ }
package/src/index.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  export * from './conf';
2
2
 
3
+ export * from './enforceTilmeld';
4
+
3
5
  export * from './errors';
4
6
 
5
7
  import AbleObject from './AbleObject';