fix: Indexes _email_verify_token for email verification and _perishable_token password reset are not created automatically (#9893)

This commit is contained in:
Manuel
2025-11-01 13:52:23 +01:00
committed by GitHub
parent 00f8d4cda9
commit 62dd3c565a
6 changed files with 192 additions and 1 deletions

View File

@@ -687,6 +687,7 @@ export class MongoStorageAdapter implements StorageAdapter {
const defaultOptions: Object = { background: true, sparse: true };
const indexNameOptions: Object = indexName ? { name: indexName } : {};
const ttlOptions: Object = options.ttl !== undefined ? { expireAfterSeconds: options.ttl } : {};
const sparseOptions: Object = options.sparse !== undefined ? { sparse: options.sparse } : {};
const caseInsensitiveOptions: Object = caseInsensitive
? { collation: MongoCollection.caseInsensitiveCollation() }
: {};
@@ -695,6 +696,7 @@ export class MongoStorageAdapter implements StorageAdapter {
...caseInsensitiveOptions,
...indexNameOptions,
...ttlOptions,
...sparseOptions,
};
return this._adaptiveCollection(className)

View File

@@ -1764,6 +1764,20 @@ class DatabaseController {
throw error;
});
await this.adapter
.ensureIndex('_User', requiredUserFields, ['_email_verify_token'], '_email_verify_token', false)
.catch(error => {
logger.warn('Unable to create index for email verification token: ', error);
throw error;
});
await this.adapter
.ensureIndex('_User', requiredUserFields, ['_perishable_token'], '_perishable_token', false)
.catch(error => {
logger.warn('Unable to create index for password reset token: ', error);
throw error;
});
await this.adapter.ensureUniqueness('_Role', requiredRoleFields, ['name']).catch(error => {
logger.warn('Unable to ensure uniqueness for role name: ', error);
throw error;