@justair/justair-library 7.15.0-alpha.4db0518 → 7.15.0
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"emailChangeToken.d.ts","sourceRoot":"","sources":["../../src/models/emailChangeToken.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"emailChangeToken.d.ts","sourceRoot":"","sources":["../../src/models/emailChangeToken.js"],"names":[],"mappings":"AA2BA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAUE;AAYF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAAoF;qBAjD/D,UAAU"}
|
package/package.json
CHANGED
|
@@ -15,9 +15,13 @@ import mongoose from 'mongoose';
|
|
|
15
15
|
// - single-use is enforced with ONE atomic operation at verify time:
|
|
16
16
|
// findOneAndUpdate({ tokenHash, used:false, expiresAt:{$gt: now} }, {$set:{used:true}})
|
|
17
17
|
// so two clicks cannot both consume the same token;
|
|
18
|
-
// -
|
|
19
|
-
//
|
|
20
|
-
//
|
|
18
|
+
// - `expiresAt` is the real expiry and verify MUST check it in the query above.
|
|
19
|
+
// The TTL index below does NOT delete at expiry: it sweeps a day later, so an
|
|
20
|
+
// expired, unclicked request stays readable and GET /admin/me can report
|
|
21
|
+
// "expired" to the profile page for that day (Figma "Email update not
|
|
22
|
+
// verified."). The lingering row holds adminId, the requested newEmail and a
|
|
23
|
+
// SHA-256 hash the consume query refuses; no raw token, nothing a client
|
|
24
|
+
// could use, but the unverified address does sit here a day longer.
|
|
21
25
|
//
|
|
22
26
|
// Requesting a second change for the same admin marks every earlier unused token
|
|
23
27
|
// used (updateMany) before minting the new one, so only the newest link works.
|
|
@@ -25,7 +29,7 @@ const emailChangeTokenSchema = new mongoose.Schema(
|
|
|
25
29
|
{
|
|
26
30
|
adminId: { type: mongoose.Types.ObjectId, ref: 'Admin', required: true, index: true },
|
|
27
31
|
// The address the admin asked to move to. Written to Admin.email at verify.
|
|
28
|
-
newEmail: { type: String, required: true },
|
|
32
|
+
newEmail: { type: String, required: true, trim: true },
|
|
29
33
|
tokenHash: { type: String, required: true, unique: true, index: true },
|
|
30
34
|
used: { type: Boolean, default: false },
|
|
31
35
|
expiresAt: { type: Date, required: true },
|
|
@@ -33,8 +37,15 @@ const emailChangeTokenSchema = new mongoose.Schema(
|
|
|
33
37
|
{ timestamps: true },
|
|
34
38
|
);
|
|
35
39
|
|
|
36
|
-
// TTL index — MongoDB removes the doc
|
|
37
|
-
|
|
40
|
+
// TTL index — MongoDB removes the doc 24h after expiresAt, not at expiresAt
|
|
41
|
+
// (see the header comment: the row must outlive the link to report "expired").
|
|
42
|
+
// MongoDB will not change expireAfterSeconds on an index that already exists:
|
|
43
|
+
// a database that built this index from a pre-release alpha (expireAfterSeconds
|
|
44
|
+
// 0) keeps deleting at expiry until it is told otherwise, once, in mongosh:
|
|
45
|
+
// db.runCommand({ collMod: 'emailchangetokens',
|
|
46
|
+
// index: { keyPattern: { expiresAt: 1 }, expireAfterSeconds: 86400 } })
|
|
47
|
+
const EXPIRED_ROW_RETENTION_SECONDS = 24 * 60 * 60;
|
|
48
|
+
emailChangeTokenSchema.index({ expiresAt: 1 }, { expireAfterSeconds: EXPIRED_ROW_RETENTION_SECONDS });
|
|
38
49
|
|
|
39
50
|
const EmailChangeToken = mongoose.model('EmailChangeToken', emailChangeTokenSchema);
|
|
40
51
|
|