Skip to content

Commit f0b2068

Browse files
committed
feat(config): add JWT secret key environment variable retrieval
- Implement jwtSecretKey getter in EnvironmentConfig class - Add error handling for missing JWT_SECRET_KEY environment variable - Include detailed error message when JWT_SECRET_KEY is not set
1 parent cedbe20 commit f0b2068

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

lib/src/config/environment_config.dart

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,24 @@ abstract final class EnvironmentConfig {
7878
return dbUrl;
7979
}
8080

81+
/// Retrieves the JWT secret key from the environment.
82+
///
83+
/// The value is read from the `JWT_SECRET_KEY` environment variable.
84+
///
85+
/// Throws a [StateError] if the `JWT_SECRET_KEY` environment variable is not
86+
/// set, as the application cannot function without it.
87+
static String get jwtSecretKey {
88+
final jwtKey = _env['JWT_SECRET_KEY'];
89+
if (jwtKey == null || jwtKey.isEmpty) {
90+
_log.severe('JWT_SECRET_KEY not found in environment variables.');
91+
throw StateError(
92+
'FATAL: JWT_SECRET_KEY environment variable is not set. '
93+
'The application cannot start without a JWT secret.',
94+
);
95+
}
96+
return jwtKey;
97+
}
98+
8199
/// Retrieves the current environment mode (e.g., 'development').
82100
///
83101
/// The value is read from the `ENV` environment variable.

0 commit comments

Comments
 (0)