corebasic 1.0.217 → 1.0.218
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/dist/libs/auth.js +6 -3
- package/dist/libs/compression.js +1 -0
- package/dist/libs/elabase.js +1 -0
- package/dist/libs/features.js +2 -0
- package/dist/libs/kafka.js +1 -0
- package/dist/libs/messaging.js +3 -1
- package/dist/libs/session.js +16 -15
- package/libs/auth.ts +6 -3
- package/libs/compression.ts +1 -0
- package/libs/dip/suffix/index.ts +1 -1
- package/libs/dip/suffix/policy.ts +3 -2
- package/libs/dip/suffix/suffix.ts +2 -2
- package/libs/dip.ts +1 -1
- package/libs/elabase.ts +5 -4
- package/libs/features.ts +2 -0
- package/libs/kafka.ts +3 -2
- package/libs/messaging.ts +4 -1
- package/libs/session.ts +13 -7
- package/package.json +1 -1
package/dist/libs/auth.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
// @ts-ignore
|
|
1
2
|
import axios from 'axios';
|
|
3
|
+
// @ts-ignore
|
|
2
4
|
import otpGenerator from 'otp-generator';
|
|
3
5
|
import * as Dip from './dip.js';
|
|
4
6
|
import * as Utils from './utils.js';
|
|
@@ -35,7 +37,8 @@ async function attemptLogin(req, res) {
|
|
|
35
37
|
let meta = { company: "GLOBAL", outlet: "GLOBAL" };
|
|
36
38
|
let expiry = 300000;
|
|
37
39
|
let userMob = req.body.mob ?? req.body.phone;
|
|
38
|
-
|
|
40
|
+
const code = req.body.code;
|
|
41
|
+
let mob = userMob.endsWith('123456789') ? '0123456789' : Utils.parseMob(userMob, code);
|
|
39
42
|
let time = new Date().getTime();
|
|
40
43
|
let collection = (req.body.app ? req.body.app + '.' : '') + "auth.login";
|
|
41
44
|
let errMessage = { success: false, message: "Login Server Error" };
|
|
@@ -52,7 +55,7 @@ async function attemptLogin(req, res) {
|
|
|
52
55
|
catch (err) {
|
|
53
56
|
throw { ...errMessage, mode: 'verify', info: 'Cleanup Failed' };
|
|
54
57
|
}
|
|
55
|
-
return { ...res[0], mode: 'verify', success: true, userId: res[0].userId, phone: res[0]._id, mob: res[0]._id };
|
|
58
|
+
return { ...res[0], mode: 'verify', success: true, userId: res[0].userId, phone: res[0]._id, mob: res[0]._id, code };
|
|
56
59
|
}
|
|
57
60
|
throw { ...errMessage, mode: 'verify', info: "Invalid/Expired OTP" };
|
|
58
61
|
}
|
|
@@ -64,7 +67,7 @@ async function attemptLogin(req, res) {
|
|
|
64
67
|
let data = req.body.data ?? {};
|
|
65
68
|
let info = { clientId, created: now, updated: now, ...data };
|
|
66
69
|
await Dip.update(meta, collection, { _id: mob }, { $set: { otp, clientId, time, updated: now, attemptLogin: true }, $setOnInsert: { _id: mob, otp, time, userId, ...info } }, { upsert: true });
|
|
67
|
-
return { mode: 'login', success: true, userId, expiry, phone: mob, mob };
|
|
70
|
+
return { mode: 'login', success: true, userId, expiry, phone: mob, mob, code };
|
|
68
71
|
}
|
|
69
72
|
throw { ...errMessage, mode: 'login', info: 'Generating Info Failed' };
|
|
70
73
|
}
|
package/dist/libs/compression.js
CHANGED
package/dist/libs/elabase.js
CHANGED
package/dist/libs/features.js
CHANGED
|
@@ -11,7 +11,9 @@ import * as Kafka from './kafka.js';
|
|
|
11
11
|
import * as Utils from './utils.js';
|
|
12
12
|
import * as Session from './session.js';
|
|
13
13
|
import * as Messaging from './messaging.js';
|
|
14
|
+
// @ts-ignore
|
|
14
15
|
import axios from 'axios';
|
|
16
|
+
// @ts-ignore
|
|
15
17
|
import jwt from 'jsonwebtoken';
|
|
16
18
|
let features = {};
|
|
17
19
|
let apis = {};
|
package/dist/libs/kafka.js
CHANGED
package/dist/libs/messaging.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
import * as Utils from './utils.js';
|
|
2
|
+
// @ts-ignore
|
|
1
3
|
import axios from 'axios';
|
|
4
|
+
// @ts-ignore
|
|
2
5
|
import { createClient } from 'redis';
|
|
3
|
-
import * as Utils from './utils.js';
|
|
4
6
|
const url = process.env.REDIS_URL || "redis://localhost:6380";
|
|
5
7
|
// url: 'redis://alice:foobared@localhost:6380'
|
|
6
8
|
let consumer, publisher;
|
package/dist/libs/session.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import jwt from 'jsonwebtoken';
|
|
2
1
|
import * as Utils from './utils.js';
|
|
3
2
|
import * as Features from './features.js';
|
|
3
|
+
// @ts-ignore
|
|
4
|
+
import jwt from 'jsonwebtoken';
|
|
4
5
|
let app;
|
|
5
6
|
const ACCESS_TOKEN_SECRET = process.env.JWT_ACCESS_TOKEN_SECRET || "MY_SECRET_ACCESS_TOKEN";
|
|
6
7
|
const REFRESH_TOKEN_SECRET = process.env.JWT_REFRESH_TOKEN_SECRET || "MY_SECRET_REFRESH_TOKEN";
|
|
@@ -27,13 +28,13 @@ export const start = (expressApp, allowedUrls) => {
|
|
|
27
28
|
try {
|
|
28
29
|
const token = req.header('JWT'); // 'Authorization' for Spring Boot, 'x-access-token' for Node.js Express back-end
|
|
29
30
|
const service = req.header('SERVICE'); // Case insensitive search
|
|
30
|
-
const additionalValidation = async (
|
|
31
|
+
const additionalValidation = async () => (process.env.GRANT_FULL_ACCESS || allowedDefaults || await checkPrivilege(req));
|
|
31
32
|
async function verifyDeveloperAccess() {
|
|
32
33
|
const NDCURVE_DEVELOPER_LICENSE_ACCESS_TOKEN = req.header('NDCURVE_DEVELOPER_LICENSE_ACCESS_TOKEN');
|
|
33
34
|
const isDeveloper = NDCURVE_DEVELOPER_LICENSE_ACCESS_TOKEN && NDCURVE_DEVELOPER_LICENSE_ACCESS_TOKEN_SECRET;
|
|
34
35
|
if (!isDeveloper)
|
|
35
36
|
return false;
|
|
36
|
-
const verify =
|
|
37
|
+
const verify = () => jwt.verify(NDCURVE_DEVELOPER_LICENSE_ACCESS_TOKEN, NDCURVE_DEVELOPER_LICENSE_ACCESS_TOKEN_SECRET, { algorithms: ['RS512'] });
|
|
37
38
|
try {
|
|
38
39
|
if (service && verify())
|
|
39
40
|
return true;
|
|
@@ -62,12 +63,12 @@ export const start = (expressApp, allowedUrls) => {
|
|
|
62
63
|
const decoded = jwt.verify(refreshToken, REFRESH_TOKEN_SECRET);
|
|
63
64
|
if (decoded.userId === userId && decoded.clientId === clientId) {
|
|
64
65
|
let now = Utils.now();
|
|
65
|
-
let
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
refreshTokenExpiry =
|
|
66
|
+
let _accessTokenExpiry = new Date(now);
|
|
67
|
+
_accessTokenExpiry.setDate(_accessTokenExpiry.getDate() + 1);
|
|
68
|
+
let _refreshTokenExpiry = new Date(now);
|
|
69
|
+
_refreshTokenExpiry.setDate(_refreshTokenExpiry.getDate() + 30);
|
|
70
|
+
const accessTokenExpiry = _accessTokenExpiry.getTime();
|
|
71
|
+
const refreshTokenExpiry = _refreshTokenExpiry.getTime();
|
|
71
72
|
const accessToken = jwt.sign({ userId, clientId }, ACCESS_TOKEN_SECRET, { expiresIn: '1d' });
|
|
72
73
|
const refreshToken = jwt.sign({ userId, clientId }, REFRESH_TOKEN_SECRET, { expiresIn: '30d' });
|
|
73
74
|
return res.json({ tokens: { accessToken, refreshToken, accessTokenExpiry, refreshTokenExpiry } });
|
|
@@ -84,12 +85,12 @@ export const start = (expressApp, allowedUrls) => {
|
|
|
84
85
|
export const generateAccessToken = (userId, clientId) => {
|
|
85
86
|
let data = { userId, clientId };
|
|
86
87
|
let now = Utils.now();
|
|
87
|
-
let
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
refreshTokenExpiry =
|
|
88
|
+
let _accessTokenExpiry = new Date(now);
|
|
89
|
+
_accessTokenExpiry.setDate(_accessTokenExpiry.getDate() + 1);
|
|
90
|
+
let _refreshTokenExpiry = new Date(now);
|
|
91
|
+
_refreshTokenExpiry.setDate(_refreshTokenExpiry.getDate() + 30);
|
|
92
|
+
const accessTokenExpiry = _accessTokenExpiry.getTime();
|
|
93
|
+
const refreshTokenExpiry = _refreshTokenExpiry.getTime();
|
|
93
94
|
const accessToken = jwt.sign(data, ACCESS_TOKEN_SECRET, { expiresIn: '1d' });
|
|
94
95
|
const refreshToken = jwt.sign(data, REFRESH_TOKEN_SECRET, { expiresIn: '365d' });
|
|
95
96
|
return { accessToken, refreshToken, accessTokenExpiry, refreshTokenExpiry };
|
package/libs/auth.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
// @ts-ignore
|
|
1
2
|
import axios from 'axios'
|
|
3
|
+
// @ts-ignore
|
|
2
4
|
import otpGenerator from 'otp-generator'
|
|
3
5
|
|
|
4
6
|
import * as Dip from './dip.ts'
|
|
@@ -38,7 +40,8 @@ async function attemptLogin(req, res) {
|
|
|
38
40
|
|
|
39
41
|
let expiry = 300000
|
|
40
42
|
let userMob = req.body.mob ?? req.body.phone
|
|
41
|
-
|
|
43
|
+
const code = req.body.code
|
|
44
|
+
let mob = userMob.endsWith('123456789') ? '0123456789' : Utils.parseMob(userMob, code)
|
|
42
45
|
let time = new Date().getTime()
|
|
43
46
|
let collection = (req.body.app ? req.body.app + '.' : '') + "auth.login"
|
|
44
47
|
let errMessage = {success: false, message: "Login Server Error"}
|
|
@@ -51,7 +54,7 @@ async function attemptLogin(req, res) {
|
|
|
51
54
|
let res = await Dip.query(meta, collection, { _id: mob, otp: req.body.otp, clientId, time: { $gt: time - expiry } })
|
|
52
55
|
if (res.length) {
|
|
53
56
|
try {await Dip.update(meta, collection, { _id: mob }, { $set: { otp: '', clientId: '', loggedIn: true } }) } catch (err) { throw {...errMessage, mode: 'verify', info: 'Cleanup Failed'} }
|
|
54
|
-
return {...res[0], mode: 'verify', success: true, userId: res[0].userId, phone: res[0]._id, mob: res[0]._id}
|
|
57
|
+
return {...res[0], mode: 'verify', success: true, userId: res[0].userId, phone: res[0]._id, mob: res[0]._id, code}
|
|
55
58
|
}
|
|
56
59
|
throw {...errMessage, mode: 'verify', info: "Invalid/Expired OTP"}
|
|
57
60
|
} else { // generate login
|
|
@@ -63,7 +66,7 @@ async function attemptLogin(req, res) {
|
|
|
63
66
|
let info = { clientId, created: now, updated: now, ...data}
|
|
64
67
|
await Dip.update(meta, collection, { _id: mob }, { $set: { otp, clientId, time, updated: now, attemptLogin: true }, $setOnInsert: { _id: mob, otp, time, userId, ...info } }, { upsert: true })
|
|
65
68
|
|
|
66
|
-
return {mode: 'login', success: true, userId, expiry, phone: mob, mob}
|
|
69
|
+
return {mode: 'login', success: true, userId, expiry, phone: mob, mob, code}
|
|
67
70
|
}
|
|
68
71
|
throw {...errMessage, mode: 'login', info: 'Generating Info Failed'}
|
|
69
72
|
}
|
package/libs/compression.ts
CHANGED
package/libs/dip/suffix/index.ts
CHANGED
|
@@ -72,7 +72,7 @@ function flatten_value(target_key, value, flattened, ancestor_has_id) {
|
|
|
72
72
|
}
|
|
73
73
|
|
|
74
74
|
|
|
75
|
-
export function entries(target_key, query, binary_slice) {
|
|
75
|
+
export function entries(target_key: string, query, binary_slice?: Buffer) {
|
|
76
76
|
let result = flatten_id_values(target_key, query); // extract all valid _id
|
|
77
77
|
|
|
78
78
|
// let cows = result.map(v => extract_direct_id(v, binary_slice))
|
|
@@ -88,7 +88,7 @@ export function intersects(w_values, w_bounds, q_values, q_bounds) {
|
|
|
88
88
|
|
|
89
89
|
|
|
90
90
|
// NOTE: Matching is based on intersection, not equality. A policy matches if, for every key in `when`, there exists at least one value that satisfies both the `when` constraint and the query constraint.
|
|
91
|
-
export function matchPolicy(query, when, g_obj) {
|
|
91
|
+
export function matchPolicy(query, when, g_obj?: Record<string, any>) {
|
|
92
92
|
let obj = g_obj ?? {}
|
|
93
93
|
for (let key in when) {
|
|
94
94
|
if (key === "$and" || key === "$or") {
|
|
@@ -135,8 +135,9 @@ export function matchPolicy(query, when, g_obj) {
|
|
|
135
135
|
|
|
136
136
|
|
|
137
137
|
|
|
138
|
+
type Arg = { db?: string; collection?: string; [key: string]: any }
|
|
138
139
|
|
|
139
|
-
export async function applySuffixPolicy(COLLECTIONS_JSON, collections, query, insertMode, arg) {
|
|
140
|
+
export async function applySuffixPolicy(COLLECTIONS_JSON, collections, query, insertMode?: boolean, arg?: Arg) {
|
|
140
141
|
collections = Array.isArray(collections) ? collections : [collections]
|
|
141
142
|
let suffixes = []
|
|
142
143
|
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {entries, reduceRanges, extractBounds, getNormalizedBounds} from './index.ts'
|
|
2
2
|
import {formatDate, fillDates} from './date.ts'
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
type Arg = { db?: string; collection?: string; [key: string]: any }
|
|
5
5
|
|
|
6
6
|
const EXPLICIT_SUFFIX_POLICY_TYPES = new Set([ "string", "date", "number" ]);
|
|
7
|
-
export async function suffix(doc, policies, insertMode, arg) {
|
|
7
|
+
export async function suffix(doc, policies, insertMode?: boolean, arg?: Arg) {
|
|
8
8
|
let suffixes = [""]
|
|
9
9
|
for (const policy of policies) {
|
|
10
10
|
|
package/libs/dip.ts
CHANGED
|
@@ -37,7 +37,7 @@ export const IdempotentDip = () => {
|
|
|
37
37
|
return {
|
|
38
38
|
txn: '',
|
|
39
39
|
meta: undefined,
|
|
40
|
-
new: (async function (meta, txn, blank) {
|
|
40
|
+
new: (async function (meta, txn, blank?: {blank: boolean}) {
|
|
41
41
|
this.txn = txn
|
|
42
42
|
this.meta = meta
|
|
43
43
|
return blank ? this : ((await Elabase.query(this.meta, "txns",{_id: this.txn})).length ? false : this)
|
package/libs/elabase.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// @ts-ignore
|
|
1
2
|
import axios from 'axios'
|
|
2
3
|
import {default as dipper, shard_stats as ShardStats} from './dipper.ts'
|
|
3
4
|
import * as Utils from './utils.ts'
|
|
@@ -308,7 +309,7 @@ export const operation = async (name, extras) => {
|
|
|
308
309
|
|
|
309
310
|
|
|
310
311
|
// Ported
|
|
311
|
-
export const insert = async (meta, collection, value, options, extras) => {
|
|
312
|
+
export const insert = async (meta, collection, value, options?: any, extras?: any) => {
|
|
312
313
|
|
|
313
314
|
if (!(meta instanceof DipMeta)) console.warn('Warn: Provided meta is not an instance of DipMeta in Dip.insert()') // TODO: throw error once review completes
|
|
314
315
|
|
|
@@ -352,7 +353,7 @@ export const insert = async (meta, collection, value, options, extras) => {
|
|
|
352
353
|
}
|
|
353
354
|
|
|
354
355
|
// Ported
|
|
355
|
-
export const query = async (meta, collection, query, options, extras) => {
|
|
356
|
+
export const query = async (meta, collection, query, options?: any, extras?: any) => {
|
|
356
357
|
|
|
357
358
|
if (!(meta instanceof DipMeta)) console.warn('Warn: Provided meta is not an instance of DipMeta in Dip.query()') // TODO: throw error once review completes
|
|
358
359
|
|
|
@@ -404,7 +405,7 @@ function collectionArray(col) {
|
|
|
404
405
|
}
|
|
405
406
|
|
|
406
407
|
// Ported
|
|
407
|
-
export const update = async (meta, collection, query, update, options, extras) => {
|
|
408
|
+
export const update = async (meta, collection, query, update, options?: any, extras?: any) => {
|
|
408
409
|
|
|
409
410
|
if (!(meta instanceof DipMeta)) console.warn('Warn: Provided meta is not an instance of DipMeta in Dip.update()') // TODO: throw error once review completes
|
|
410
411
|
|
|
@@ -444,7 +445,7 @@ export const update = async (meta, collection, query, update, options, extras) =
|
|
|
444
445
|
}
|
|
445
446
|
|
|
446
447
|
// Ported
|
|
447
|
-
export const remove = async (meta, collection, query, options, extras) => {
|
|
448
|
+
export const remove = async (meta, collection, query, options?: any, extras?: any) => {
|
|
448
449
|
|
|
449
450
|
if (!(meta instanceof DipMeta)) console.warn('Warn: Provided meta is not an instance of DipMeta in Dip.remove()') // TODO: throw error once review completes
|
|
450
451
|
|
package/libs/features.ts
CHANGED
|
@@ -3,7 +3,9 @@ import * as Kafka from './kafka.ts'
|
|
|
3
3
|
import * as Utils from './utils.ts'
|
|
4
4
|
import * as Session from './session.ts'
|
|
5
5
|
import * as Messaging from './messaging.ts'
|
|
6
|
+
// @ts-ignore
|
|
6
7
|
import axios from 'axios'
|
|
8
|
+
// @ts-ignore
|
|
7
9
|
import jwt from 'jsonwebtoken'
|
|
8
10
|
|
|
9
11
|
let features = {}
|
package/libs/kafka.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// @ts-ignore
|
|
1
2
|
import { Kafka, logLevel as KafkaLogLevel, CompressionTypes as KafkaCompressionTypes } from 'kafkajs'
|
|
2
3
|
|
|
3
4
|
export const logLevel = KafkaLogLevel
|
|
@@ -38,7 +39,7 @@ export const createTopic = async (topic, partition, replicas) => {
|
|
|
38
39
|
|
|
39
40
|
let consumers = []
|
|
40
41
|
|
|
41
|
-
const start_consumer = async function (topic, groupId, callback) {
|
|
42
|
+
const start_consumer = async function (topic, groupId, callback?: Function) {
|
|
42
43
|
callback = typeof groupId === "string" ? callback : groupId
|
|
43
44
|
groupId = typeof groupId === "string" ? `${appName}.${groupId}` : `${appName}.${topic}`
|
|
44
45
|
|
|
@@ -96,7 +97,7 @@ const start_producer = async function (topic, message, key, options) {
|
|
|
96
97
|
// start_consumer('quickstart-events')
|
|
97
98
|
// start_producer('quickstart-events', 'Hello KafkaJS user! Little')
|
|
98
99
|
|
|
99
|
-
export const receive = async function(topic, groupId, callback) {
|
|
100
|
+
export const receive = async function(topic, groupId, callback?: Function) {
|
|
100
101
|
topic = topicPrefix + topic
|
|
101
102
|
return (await start_consumer(topic, groupId, callback))
|
|
102
103
|
}
|
package/libs/messaging.ts
CHANGED
package/libs/session.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import jwt from 'jsonwebtoken'
|
|
2
1
|
import * as Utils from './utils.ts'
|
|
3
2
|
import * as Features from './features.ts'
|
|
3
|
+
// @ts-ignore
|
|
4
|
+
import jwt from 'jsonwebtoken'
|
|
5
|
+
|
|
4
6
|
let app
|
|
5
7
|
|
|
6
8
|
|
|
@@ -42,14 +44,14 @@ export const start = (expressApp, allowedUrls) => {
|
|
|
42
44
|
try {
|
|
43
45
|
const token = req.header('JWT'); // 'Authorization' for Spring Boot, 'x-access-token' for Node.js Express back-end
|
|
44
46
|
const service = req.header('SERVICE'); // Case insensitive search
|
|
45
|
-
const additionalValidation = async
|
|
47
|
+
const additionalValidation = async () => (process.env.GRANT_FULL_ACCESS || allowedDefaults || await checkPrivilege(req))
|
|
46
48
|
|
|
47
49
|
async function verifyDeveloperAccess() {
|
|
48
50
|
const NDCURVE_DEVELOPER_LICENSE_ACCESS_TOKEN = req.header('NDCURVE_DEVELOPER_LICENSE_ACCESS_TOKEN')
|
|
49
51
|
const isDeveloper = NDCURVE_DEVELOPER_LICENSE_ACCESS_TOKEN && NDCURVE_DEVELOPER_LICENSE_ACCESS_TOKEN_SECRET
|
|
50
52
|
if (!isDeveloper)
|
|
51
53
|
return false
|
|
52
|
-
const verify =
|
|
54
|
+
const verify = () => jwt.verify(NDCURVE_DEVELOPER_LICENSE_ACCESS_TOKEN, NDCURVE_DEVELOPER_LICENSE_ACCESS_TOKEN_SECRET, { algorithms: ['RS512'] })
|
|
53
55
|
try {
|
|
54
56
|
if (service && verify())
|
|
55
57
|
return true
|
|
@@ -79,8 +81,10 @@ export const start = (expressApp, allowedUrls) => {
|
|
|
79
81
|
const decoded = jwt.verify(refreshToken, REFRESH_TOKEN_SECRET)
|
|
80
82
|
if (decoded.userId === userId && decoded.clientId === clientId) {
|
|
81
83
|
let now = Utils.now()
|
|
82
|
-
let
|
|
83
|
-
let
|
|
84
|
+
let _accessTokenExpiry = new Date(now); _accessTokenExpiry.setDate(_accessTokenExpiry.getDate() + 1);
|
|
85
|
+
let _refreshTokenExpiry = new Date(now); _refreshTokenExpiry.setDate(_refreshTokenExpiry.getDate() + 30);
|
|
86
|
+
const accessTokenExpiry = _accessTokenExpiry.getTime()
|
|
87
|
+
const refreshTokenExpiry = _refreshTokenExpiry.getTime()
|
|
84
88
|
const accessToken = jwt.sign({ userId, clientId }, ACCESS_TOKEN_SECRET, { expiresIn: '1d' });
|
|
85
89
|
const refreshToken = jwt.sign({ userId, clientId }, REFRESH_TOKEN_SECRET, { expiresIn: '30d' });
|
|
86
90
|
return res.json({ tokens: { accessToken, refreshToken, accessTokenExpiry, refreshTokenExpiry} });
|
|
@@ -100,8 +104,10 @@ export const generateAccessToken = (userId, clientId) => {
|
|
|
100
104
|
let data = { userId, clientId }
|
|
101
105
|
|
|
102
106
|
let now = Utils.now()
|
|
103
|
-
let
|
|
104
|
-
let
|
|
107
|
+
let _accessTokenExpiry = new Date(now); _accessTokenExpiry.setDate(_accessTokenExpiry.getDate() + 1);
|
|
108
|
+
let _refreshTokenExpiry = new Date(now); _refreshTokenExpiry.setDate(_refreshTokenExpiry.getDate() + 30);
|
|
109
|
+
const accessTokenExpiry = _accessTokenExpiry.getTime()
|
|
110
|
+
const refreshTokenExpiry = _refreshTokenExpiry.getTime()
|
|
105
111
|
|
|
106
112
|
const accessToken = jwt.sign(data, ACCESS_TOKEN_SECRET, { expiresIn: '1d' });
|
|
107
113
|
const refreshToken = jwt.sign(data, REFRESH_TOKEN_SECRET, { expiresIn: '365d' });
|