corebasic 1.0.22 → 1.0.24
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/libs/auth.js +5 -5
- package/package.json +1 -1
package/libs/auth.js
CHANGED
|
@@ -35,13 +35,13 @@ module.exports.start = (app, successCallback) => {
|
|
|
35
35
|
|
|
36
36
|
async function attemptLogin(req, res) {
|
|
37
37
|
let expiry = 300000
|
|
38
|
-
let phone = req.body.phone
|
|
38
|
+
let phone = req.body.phone.trim()
|
|
39
39
|
let time = new Date().getTime()
|
|
40
40
|
let collection = (req.body.app ? req.body.app + '.' : '') + "auth.login"
|
|
41
41
|
if (req.body.otp) { // verify login
|
|
42
|
-
let res = await Elabase.query(collection, { _id: phone
|
|
42
|
+
let res = await Elabase.query(collection, { _id: phone, otp: req.body.otp, time: { $gt: time - expiry } })
|
|
43
43
|
if (res.length)
|
|
44
|
-
return {mode: 'verify', success: true, userId: res[0].userId}
|
|
44
|
+
return {mode: 'verify', success: true, userId: res[0].userId, position: res[0].position, phone: res[0].phone}
|
|
45
45
|
throw {mode: 'verify', success: false, msg: "Invalid OTP"}
|
|
46
46
|
} else { // generate login
|
|
47
47
|
let otp = phone === '0123456789' ? '1234' : otpGenerator.generate(4, { upperCaseAlphabets: false, specialChars: false, digital: true, lowerCaseAlphabets: false });
|
|
@@ -50,8 +50,8 @@ async function attemptLogin(req, res) {
|
|
|
50
50
|
let now = Utils.now().toISOString()
|
|
51
51
|
let data = req.body.data ?? {}
|
|
52
52
|
let meta = {createdAt: now, updatedAt: now, pos: req.body.pos ?? undefined, ...data}
|
|
53
|
-
await Elabase.update(collection, { _id: phone
|
|
54
|
-
return {mode: 'login', success: true, userId, expiry}
|
|
53
|
+
await Elabase.update(collection, { _id: phone }, { $set: { otp, time, updatedAt: now }, $setOnInsert: { _id: phone, otp, time, userId, ...meta } }, { upsert: true })
|
|
54
|
+
return {mode: 'login', success: true, userId, expiry, phone}
|
|
55
55
|
}
|
|
56
56
|
throw {mode: 'login', success: false, msg: "Login Server Error"}
|
|
57
57
|
}
|