@things-factory/auth-base 6.2.27 → 6.2.30

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@things-factory/auth-base",
3
- "version": "6.2.27",
3
+ "version": "6.2.30",
4
4
  "main": "dist-server/index.js",
5
5
  "browser": "dist-client/index.js",
6
6
  "things-factory": true,
@@ -42,5 +42,5 @@
42
42
  "passport-jwt": "^4.0.0",
43
43
  "passport-local": "^1.0.0"
44
44
  },
45
- "gitHead": "6d414311ca45c329e93606fe46edd7ea53c819c5"
45
+ "gitHead": "6dcd4ae0df733f128ec362e88cae5267added386"
46
46
  }
@@ -1,13 +1,17 @@
1
1
  import passport from 'koa-passport'
2
2
  import { ExtractJwt, Strategy as JWTstrategy } from 'passport-jwt'
3
3
 
4
+ import { config } from '@things-factory/env'
5
+
4
6
  import { makeVerificationToken } from '../controllers/utils/make-verification-token'
5
7
  import { saveVerificationToken } from '../controllers/utils/save-verification-token'
6
8
  import { User, UserStatus } from '../service/user/user'
7
9
  import { VerificationTokenType } from '../service/verification-token/verification-token'
8
- import { clearAccessTokenCookie, getAccessTokenCookie } from '../utils/access-token-cookie'
10
+ import { clearAccessTokenCookie, getAccessTokenCookie, setAccessTokenCookie } from '../utils/access-token-cookie'
9
11
  import { SECRET } from '../utils/get-secret'
10
12
 
13
+ const sessionExpiryPolicy = config.get('session/expiryPolicy', 'fixed')
14
+
11
15
  passport.use(
12
16
  new JWTstrategy(
13
17
  {
@@ -65,6 +69,14 @@ export async function jwtAuthenticateMiddleware(context, next) {
65
69
  } else {
66
70
  context.state.user = userEntity
67
71
  context.state.decodedToken = decoded
72
+
73
+ if (sessionExpiryPolicy == 'rolling') {
74
+ /* To renew the expiry time on each request, a token is issued and the session is updated. */
75
+
76
+ const token = await userEntity.sign()
77
+ setAccessTokenCookie(context, token)
78
+ }
79
+
68
80
  await next()
69
81
  }
70
82
  }
@@ -28,6 +28,8 @@ import { getDomainsWithPrivilege } from '../../utils/get-user-domains'
28
28
  const ORMCONFIG = config.get('ormconfig', {})
29
29
  const DATABASE_TYPE = ORMCONFIG.type
30
30
 
31
+ const sessionExpirySeconds = Number(config.get('session/expirySeconds')) || '7d'
32
+
31
33
  export enum UserStatus {
32
34
  INACTIVE = 'inactive',
33
35
  ACTIVATED = 'activated',
@@ -164,7 +166,7 @@ export class User {
164
166
 
165
167
  /* signing for jsonwebtoken */
166
168
  async sign(options?) {
167
- var { expiresIn = '7d', subdomain } = options || {}
169
+ var { expiresIn = sessionExpirySeconds, subdomain } = options || {}
168
170
 
169
171
  var user = {
170
172
  id: this.id,