corebasic 1.0.19 → 1.0.21
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 +4 -3
- package/package.json +1 -1
package/libs/auth.js
CHANGED
|
@@ -20,7 +20,7 @@ module.exports.start = (app, successCallback) => {
|
|
|
20
20
|
let login = await attemptLogin(req, res)
|
|
21
21
|
if (login.mode === 'verify' && login.success) {
|
|
22
22
|
let tokens = Session.generateAccessToken(login.userId, req.body.clientId)
|
|
23
|
-
let response = {
|
|
23
|
+
let response = {...login, tokens}
|
|
24
24
|
if (successCallback)
|
|
25
25
|
await successCallback(req, res, response)
|
|
26
26
|
else
|
|
@@ -48,7 +48,8 @@ async function attemptLogin(req, res) {
|
|
|
48
48
|
if (await sendOtp(phone, otp)) {
|
|
49
49
|
let userId = req.body.userId ?? Utils.uid()
|
|
50
50
|
let now = Utils.now().toISOString()
|
|
51
|
-
let
|
|
51
|
+
let data = req.body.data ?? {}
|
|
52
|
+
let meta = {createdAt: now, updatedAt: now, pos: req.body.pos ?? undefined, ...data}
|
|
52
53
|
await Elabase.update(collection, { _id: phone.trim() }, { $set: { otp, time, updatedAt: now }, $setOnInsert: { _id: phone.trim(), otp, time, userId, ...meta } }, { upsert: true })
|
|
53
54
|
return {mode: 'login', success: true, userId, expiry}
|
|
54
55
|
}
|
|
@@ -71,7 +72,7 @@ async function sendOtp(phone, otp) {
|
|
|
71
72
|
|
|
72
73
|
// API
|
|
73
74
|
// ----
|
|
74
|
-
// Login => HttpRequest.post('/login').send({app: '', clientId: '', phone: '', userId: 'Optional'}) // Response => { mode: 'login', success, userId }
|
|
75
|
+
// Login => HttpRequest.post('/login').send({app: '', clientId: '', phone: '', userId: 'Optional', data: {//optional} }) // Response => { mode: 'login', success, userId, expiry }
|
|
75
76
|
// Verify => HttpRequest.post('/login').send({app: '', clientId: '', phone: '', otp: ''}) // Response => { mode: 'verify', success, userId }
|
|
76
77
|
|
|
77
78
|
// Usage
|