Skip to content

Commit 227108c

Browse files
committed
style: format
1 parent e9f7144 commit 227108c

8 files changed

+40
-83
lines changed

lib/src/config/environment_config.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,7 @@ abstract final class EnvironmentConfig {
113113
///
114114
/// The value is read from the `JWT_ISSUER` environment variable.
115115
/// Defaults to 'http://localhost:8080' if not set.
116-
static String get jwtIssuer =>
117-
_env['JWT_ISSUER'] ?? 'http://localhost:8080';
116+
static String get jwtIssuer => _env['JWT_ISSUER'] ?? 'http://localhost:8080';
118117

119118
/// Retrieves the JWT expiry duration in hours from the environment.
120119
///

lib/src/middlewares/authentication_middleware.dart

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,7 @@ Middleware authenticationProvider() {
4747
_log.finer('Attempting to validate token...');
4848
// Validate the token using the service
4949
user = await tokenService.validateToken(token);
50-
_log.finer(
51-
'Token validation returned: ${user?.id ?? 'null'}',
52-
);
50+
_log.finer('Token validation returned: ${user?.id ?? 'null'}');
5351
if (user != null) {
5452
_log.info('Authentication successful for user: ${user.id}');
5553
} else {
@@ -68,11 +66,7 @@ Middleware authenticationProvider() {
6866
user = null; // Keep user null if HtHttpException occurred
6967
} catch (e, s) {
7068
// Catch unexpected errors during validation
71-
_log.severe(
72-
'Unexpected error during token validation.',
73-
e,
74-
s,
75-
);
69+
_log.severe('Unexpected error during token validation.', e, s);
7670
user = null; // Keep user null if unexpected error occurred
7771
}
7872
} else {
@@ -81,9 +75,7 @@ Middleware authenticationProvider() {
8175

8276
// Provide the User object (or null) into the context
8377
// This makes `context.read<User?>()` available downstream.
84-
_log.finer(
85-
'Providing User (${user?.id ?? 'null'}) to context.',
86-
);
78+
_log.finer('Providing User (${user?.id ?? 'null'}) to context.');
8779
return handler(context.provide<User?>(() => user));
8880
};
8981
};

lib/src/services/auth_service.dart

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// ignore_for_file: inference_failure_on_untyped_parameter
2+
13
import 'dart:async';
24

35
import 'package:ht_api/src/config/environment_config.dart';
@@ -154,10 +156,12 @@ class AuthService {
154156
String? currentToken,
155157
}) async {
156158
// 1. Validate the verification code.
157-
final isValidCode =
158-
await _verificationCodeStorageService.validateSignInCode(email, code);
159+
final isValidCode = await _verificationCodeStorageService
160+
.validateSignInCode(email, code);
159161
if (!isValidCode) {
160-
throw const InvalidInputException('Invalid or expired verification code.');
162+
throw const InvalidInputException(
163+
'Invalid or expired verification code.',
164+
);
161165
}
162166

163167
// After successful validation, clear the code from storage.

lib/src/services/database_seeding_service.dart

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -128,22 +128,19 @@ class DatabaseSeedingService {
128128
_log.info('Ensuring database indexes exist...');
129129
try {
130130
// Text index for searching headlines by title
131-
await _db.collection('headlines').createIndex(
132-
keys: {'title': 'text'},
133-
name: 'headlines_text_index',
134-
);
131+
await _db
132+
.collection('headlines')
133+
.createIndex(keys: {'title': 'text'}, name: 'headlines_text_index');
135134

136135
// Text index for searching topics by name
137-
await _db.collection('topics').createIndex(
138-
keys: {'name': 'text'},
139-
name: 'topics_text_index',
140-
);
136+
await _db
137+
.collection('topics')
138+
.createIndex(keys: {'name': 'text'}, name: 'topics_text_index');
141139

142140
// Text index for searching sources by name
143-
await _db.collection('sources').createIndex(
144-
keys: {'name': 'text'},
145-
name: 'sources_text_index',
146-
);
141+
await _db
142+
.collection('sources')
143+
.createIndex(keys: {'name': 'text'}, name: 'sources_text_index');
147144

148145
// --- TTL and Unique Indexes via runCommand ---
149146
// The following indexes are created using the generic `runCommand` because
@@ -169,8 +166,8 @@ class DatabaseSeedingService {
169166
'key': {'email': 1},
170167
'name': 'email_unique_index',
171168
'unique': true,
172-
}
173-
]
169+
},
170+
],
174171
});
175172

176173
// Index for the token blacklist collection
@@ -183,8 +180,8 @@ class DatabaseSeedingService {
183180
'key': {'expiry': 1},
184181
'name': 'expiry_ttl_index',
185182
'expireAfterSeconds': 0,
186-
}
187-
]
183+
},
184+
],
188185
});
189186

190187
_log.info('Database indexes are set up correctly.');

lib/src/services/mongodb_token_blacklist_service.dart

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ class MongoDbTokenBlacklistService implements TokenBlacklistService {
2121
MongoDbTokenBlacklistService({
2222
required MongoDbConnectionManager connectionManager,
2323
required Logger log,
24-
}) : _connectionManager = connectionManager,
25-
_log = log;
24+
}) : _connectionManager = connectionManager,
25+
_log = log;
2626

2727
final MongoDbConnectionManager _connectionManager;
2828
final Logger _log;
@@ -35,19 +35,14 @@ class MongoDbTokenBlacklistService implements TokenBlacklistService {
3535
try {
3636
// The document structure is simple: the JTI is the primary key (_id)
3737
// and `expiry` is the TTL-indexed field.
38-
await _collection.insertOne({
39-
'_id': jti,
40-
'expiry': expiry,
41-
});
38+
await _collection.insertOne({'_id': jti, 'expiry': expiry});
4239
_log.info('Blacklisted jti: $jti (expires: $expiry)');
4340
} on MongoDartError catch (e) {
4441
// Handle the specific case of a duplicate key error, which means the
4542
// token is already blacklisted. This is not a failure condition.
4643
// We check the message because the error type may not be specific enough.
4744
if (e.message.contains('duplicate key')) {
48-
_log.warning(
49-
'Attempted to blacklist an already blacklisted jti: $jti',
50-
);
45+
_log.warning('Attempted to blacklist an already blacklisted jti: $jti');
5146
// Swallow the exception as the desired state is already achieved.
5247
return;
5348
}

lib/src/services/mongodb_verification_code_storage_service.dart

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ class MongoDbVerificationCodeStorageService
2424
required MongoDbConnectionManager connectionManager,
2525
required Logger log,
2626
this.codeExpiryDuration = const Duration(minutes: 15),
27-
}) : _connectionManager = connectionManager,
28-
_log = log;
27+
}) : _connectionManager = connectionManager,
28+
_log = log;
2929

3030
final MongoDbConnectionManager _connectionManager;
3131
final Logger _log;
@@ -61,9 +61,7 @@ class MongoDbVerificationCodeStorageService
6161
.setOnInsert('_id', ObjectId()),
6262
upsert: true,
6363
);
64-
_log.info(
65-
'Stored sign-in code for $email (expires: $expiresAt)',
66-
);
64+
_log.info('Stored sign-in code for $email (expires: $expiresAt)');
6765
return code;
6866
} catch (e) {
6967
_log.severe('Failed to store sign-in code for $email: $e');

lib/src/services/verification_code_storage_service.dart

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,8 @@
11
// ignore_for_file: library_private_types_in_public_api
22

33
import 'dart:async';
4-
import 'dart:math';
54

65
import 'package:ht_shared/ht_shared.dart';
7-
import 'package:meta/meta.dart';
8-
9-
// Default duration for code expiry (e.g., 15 minutes)
10-
const _defaultCodeExpiryDuration = Duration(minutes: 15);
11-
// Default interval for cleaning up expired codes (e.g., 1 hour)
12-
const _defaultCleanupInterval = Duration(hours: 1);
13-
14-
/// {@template code_entry_base}
15-
/// Base class for storing verification code entries.
16-
/// {@endtemplate}
17-
class _CodeEntryBase {
18-
/// {@macro code_entry_base}
19-
_CodeEntryBase(this.code, this.expiresAt);
20-
21-
final String code;
22-
final DateTime expiresAt;
23-
24-
bool get isExpired => DateTime.now().isAfter(expiresAt);
25-
}
26-
27-
/// {@template sign_in_code_entry}
28-
/// Stores a verification code for standard email sign-in.
29-
/// {@endtemplate}
30-
class _SignInCodeEntry extends _CodeEntryBase {
31-
/// {@macro sign_in_code_entry}
32-
_SignInCodeEntry(super.code, super.expiresAt);
33-
}
346

357
/// {@template verification_code_storage_service}
368
/// Defines the interface for a service that manages verification codes

routes/api/v1/data/[id]/index.dart

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -467,15 +467,15 @@ Future<Response> _handleDelete(
467467
final repo = context.read<HtDataRepository<RemoteConfig>>();
468468
itemToDelete = await repo.read(
469469
id: id,
470-
userId: userIdForRepoCall,
471-
); // userId should be null for AppConfig
472-
default:
473-
_logger.severe(
474-
'Unsupported model type "$modelName" reached _handleDelete ownership check.',
475-
);
476-
// Throw an exception to be caught by the errorHandler
477-
throw OperationFailedException(
478-
'Unsupported model type "$modelName" reached handler.',
470+
userId: userIdForRepoCall,
471+
); // userId should be null for AppConfig
472+
default:
473+
_logger.severe(
474+
'Unsupported model type "$modelName" reached _handleDelete ownership check.',
475+
);
476+
// Throw an exception to be caught by the errorHandler
477+
throw OperationFailedException(
478+
'Unsupported model type "$modelName" reached handler.',
479479
);
480480
}
481481

0 commit comments

Comments
 (0)