@@ -25,9 +25,7 @@ class MongoDbVerificationCodeStorageService
2525 required Logger log,
2626 this .codeExpiryDuration = const Duration (minutes: 15 ),
2727 }) : _connectionManager = connectionManager,
28- _log = log {
29- _init ();
30- }
28+ _log = log;
3129
3230 final MongoDbConnectionManager _connectionManager;
3331 final Logger _log;
@@ -39,39 +37,6 @@ class MongoDbVerificationCodeStorageService
3937 DbCollection get _collection =>
4038 _connectionManager.db.collection (kVerificationCodesCollection);
4139
42- /// Initializes the service by ensuring required indexes exist.
43- Future <void > _init () async {
44- try {
45- _log.info ('Ensuring indexes exist for verification codes...' );
46- final command = {
47- 'createIndexes' : kVerificationCodesCollection,
48- 'indexes' : [
49- // TTL index for automatic document expiration
50- {
51- 'key' : {'expiresAt' : 1 },
52- 'name' : 'expiresAt_ttl_index' ,
53- 'expireAfterSeconds' : 0 ,
54- },
55- // Unique index to ensure only one code per email
56- {
57- 'key' : {'email' : 1 },
58- 'name' : 'email_unique_index' ,
59- 'unique' : true ,
60- }
61- ]
62- };
63- await _connectionManager.db.runCommand (command);
64- _log.info ('Verification codes indexes are set up correctly.' );
65- } catch (e, s) {
66- _log.severe (
67- 'Failed to create indexes for verification codes collection.' ,
68- e,
69- s,
70- );
71- rethrow ;
72- }
73- }
74-
7540 String _generateNumericCode ({int length = 6 }) {
7641 final buffer = StringBuffer ();
7742 for (var i = 0 ; i < length; i++ ) {
0 commit comments