corebasic 1.0.28 → 1.0.29

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.
Files changed (2) hide show
  1. package/libs/auth.js +9 -5
  2. package/package.json +1 -1
package/libs/auth.js CHANGED
@@ -40,11 +40,15 @@ async function attemptLogin(req, res) {
40
40
  let collection = (req.body.app ? req.body.app + '.' : '') + "auth.login"
41
41
  let errMessage = {success: false, message: "Login Server Error"}
42
42
  let otpValid = Utils.isEmpty(req.body.otp) ? false : true
43
+ let clientId = req.body.clientId
44
+ if (Utils.isEmpty(clientId))
45
+ throw { ...errMessage, mode: otpValid ? 'verify' : 'login', info: "Invalid Client ID" }
46
+
43
47
  if (otpValid) { // verify login
44
- let res = await Elabase.query(collection, { _id: phone, otp: req.body.otp, time: { $gt: time - expiry } })
48
+ let res = await Elabase.query(collection, { _id: phone, otp: req.body.otp, clientId, time: { $gt: time - expiry } })
45
49
  if (res.length) {
46
- try {await Elabase.update(collection, { _id: phone }, { $set: { otp: '' } }) } catch (err) { throw {...errMessage, mode: 'verify', info: 'Cleanup Failed'} }
47
- return {...res[0], mode: 'verify', success: true, userId: res[0].userId, position: res[0].position, phone: res[0]._id}
50
+ try {await Elabase.update(collection, { _id: phone }, { $set: { otp: '', clientId: '' } }) } catch (err) { throw {...errMessage, mode: 'verify', info: 'Cleanup Failed'} }
51
+ return {...res[0], mode: 'verify', success: true, userId: res[0].userId, phone: res[0]._id}
48
52
  }
49
53
  throw {...errMessage, mode: 'verify', info: "Invalid/Expired OTP"}
50
54
  } else { // generate login
@@ -53,8 +57,8 @@ async function attemptLogin(req, res) {
53
57
  let userId = req.body.userId ?? Utils.uid()
54
58
  let now = Utils.now().toISOString()
55
59
  let data = req.body.data ?? {}
56
- let meta = {createdAt: now, updatedAt: now, pos: req.body.pos ?? undefined, ...data}
57
- await Elabase.update(collection, { _id: phone }, { $set: { otp, time, updatedAt: now }, $setOnInsert: { _id: phone, otp, time, userId, ...meta } }, { upsert: true })
60
+ let meta = { clientId, createdAt: now, updatedAt: now, ...data}
61
+ await Elabase.update(collection, { _id: phone }, { $set: { otp, clientId, time, updatedAt: now }, $setOnInsert: { _id: phone, otp, time, userId, ...meta } }, { upsert: true })
58
62
  return {mode: 'login', success: true, userId, expiry, phone}
59
63
  }
60
64
  throw {...errMessage, mode: 'login', info: 'Generating Info Failed'}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "corebasic",
3
- "version": "1.0.28",
3
+ "version": "1.0.29",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {