@teincfood/core 0.10.6 → 0.10.7
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/offline/store.js +10 -5
- package/package.json +1 -1
package/dist/offline/store.js
CHANGED
|
@@ -204,8 +204,9 @@ export async function createOfflineMemberCredential(args) {
|
|
|
204
204
|
export const OFFLINE_PIN_MAX_ATTEMPTS = 5;
|
|
205
205
|
export async function getOfflinePinLockState(userId, businessId) {
|
|
206
206
|
const member = await getOfflineMember(userId, businessId);
|
|
207
|
-
const
|
|
208
|
-
const
|
|
207
|
+
const lockExpired = Boolean(member?.locked_until && new Date(member.locked_until).getTime() <= Date.now());
|
|
208
|
+
const failedAttempts = lockExpired ? 0 : member?.failed_attempts ?? 0;
|
|
209
|
+
const lockedUntil = lockExpired ? null : member?.locked_until ?? null;
|
|
209
210
|
const locked = Boolean(lockedUntil && new Date(lockedUntil).getTime() > Date.now());
|
|
210
211
|
return {
|
|
211
212
|
failedAttempts,
|
|
@@ -215,12 +216,16 @@ export async function getOfflinePinLockState(userId, businessId) {
|
|
|
215
216
|
};
|
|
216
217
|
}
|
|
217
218
|
export async function verifyOfflineMemberPin(userId, pin, businessId) {
|
|
218
|
-
const
|
|
219
|
-
if (!
|
|
219
|
+
const stored = await getOfflineMember(userId, businessId);
|
|
220
|
+
if (!stored)
|
|
220
221
|
return false;
|
|
221
|
-
if (
|
|
222
|
+
if (stored.locked_until && new Date(stored.locked_until).getTime() > Date.now()) {
|
|
222
223
|
return false;
|
|
223
224
|
}
|
|
225
|
+
// An expired cooldown grants a fresh set of attempts.
|
|
226
|
+
const member = stored.locked_until && new Date(stored.locked_until).getTime() <= Date.now()
|
|
227
|
+
? { ...stored, failed_attempts: 0, locked_until: null }
|
|
228
|
+
: stored;
|
|
224
229
|
if (!/^\d{6}$/.test(pin)) {
|
|
225
230
|
await recordFailedPinAttempt(member);
|
|
226
231
|
return false;
|
package/package.json
CHANGED