@@ -22,48 +22,14 @@ class MongoDbTokenBlacklistService implements TokenBlacklistService {
2222 required MongoDbConnectionManager connectionManager,
2323 required Logger log,
2424 }) : _connectionManager = connectionManager,
25- _log = log {
26- // Fire-and-forget initialization. Errors are logged internally.
27- _init ();
28- }
25+ _log = log;
2926
3027 final MongoDbConnectionManager _connectionManager;
3128 final Logger _log;
3229
3330 DbCollection get _collection =>
3431 _connectionManager.db.collection (kBlacklistedTokensCollection);
3532
36- /// Initializes the service by ensuring the TTL index exists.
37- /// This is idempotent and safe to call multiple times.
38- Future <void > _init () async {
39- try {
40- _log.info ('Ensuring TTL index exists for blacklist collection...' );
41- // Using a raw command is more robust against client library changes.
42- final command = {
43- 'createIndexes' : kBlacklistedTokensCollection,
44- 'indexes' : [
45- {
46- 'key' : {'expiry' : 1 },
47- 'name' : 'expiry_ttl_index' ,
48- 'expireAfterSeconds' : 0 ,
49- }
50- ]
51- };
52- await _connectionManager.db.runCommand (command);
53- _log.info ('Blacklist TTL index is set up correctly.' );
54- } catch (e, s) {
55- _log.severe (
56- 'Failed to create TTL index for blacklist collection. '
57- 'Failed to create TTL index for blacklist collection. '
58- 'Automatic cleanup of expired tokens will not work.' ,
59- e,
60- s,
61- );
62- // Rethrow the exception to halt startup if the index is critical.
63- rethrow ;
64- }
65- }
66-
6733 @override
6834 Future <void > blacklist (String jti, DateTime expiry) async {
6935 try {
0 commit comments