@@ -60,41 +60,32 @@ abstract final class EnvironmentConfig {
60
60
return env; // Return even if fallback
61
61
}
62
62
63
+ static String _getRequiredEnv (String key) {
64
+ final value = _env[key];
65
+ if (value == null || value.isEmpty) {
66
+ _log.severe ('$key not found in environment variables.' );
67
+ throw StateError (
68
+ 'FATAL: $key environment variable is not set.' ,
69
+ );
70
+ }
71
+ return value;
72
+ }
73
+
63
74
/// Retrieves the database connection URI from the environment.
64
75
///
65
76
/// The value is read from the `DATABASE_URL` environment variable.
66
77
///
67
78
/// Throws a [StateError] if the `DATABASE_URL` environment variable is not
68
79
/// set, as the application cannot function without it.
69
- static String get databaseUrl {
70
- final dbUrl = _env['DATABASE_URL' ];
71
- if (dbUrl == null || dbUrl.isEmpty) {
72
- _log.severe ('DATABASE_URL not found in environment variables.' );
73
- throw StateError (
74
- 'FATAL: DATABASE_URL environment variable is not set. '
75
- 'The application cannot start without a database connection.' ,
76
- );
77
- }
78
- return dbUrl;
79
- }
80
+ static String get databaseUrl => _getRequiredEnv ('DATABASE_URL' );
80
81
81
82
/// Retrieves the JWT secret key from the environment.
82
83
///
83
84
/// The value is read from the `JWT_SECRET_KEY` environment variable.
84
85
///
85
86
/// Throws a [StateError] if the `JWT_SECRET_KEY` environment variable is not
86
87
/// 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
- }
88
+ static String get jwtSecretKey => _getRequiredEnv ('JWT_SECRET_KEY' );
98
89
99
90
/// Retrieves the current environment mode (e.g., 'development').
100
91
///
@@ -127,44 +118,18 @@ abstract final class EnvironmentConfig {
127
118
/// Retrieves the SendGrid API key from the environment.
128
119
///
129
120
/// Throws a [StateError] if the `SENDGRID_API_KEY` is not set.
130
- static String get sendGridApiKey {
131
- final apiKey = _env['SENDGRID_API_KEY' ];
132
- if (apiKey == null || apiKey.isEmpty) {
133
- _log.severe ('SENDGRID_API_KEY not found in environment variables.' );
134
- throw StateError (
135
- 'FATAL: SENDGRID_API_KEY environment variable is not set.' ,
136
- );
137
- }
138
- return apiKey;
139
- }
121
+ static String get sendGridApiKey => _getRequiredEnv ('SENDGRID_API_KEY' );
140
122
141
123
/// Retrieves the default sender email from the environment.
142
124
///
143
125
/// Throws a [StateError] if the `DEFAULT_SENDER_EMAIL` is not set.
144
- static String get defaultSenderEmail {
145
- final email = _env['DEFAULT_SENDER_EMAIL' ];
146
- if (email == null || email.isEmpty) {
147
- _log.severe ('DEFAULT_SENDER_EMAIL not found in environment variables.' );
148
- throw StateError (
149
- 'FATAL: DEFAULT_SENDER_EMAIL environment variable is not set.' ,
150
- );
151
- }
152
- return email;
153
- }
126
+ static String get defaultSenderEmail =>
127
+ _getRequiredEnv ('DEFAULT_SENDER_EMAIL' );
154
128
155
129
/// Retrieves the SendGrid OTP template ID from the environment.
156
130
///
157
131
/// Throws a [StateError] if the `OTP_TEMPLATE_ID` is not set.
158
- static String get otpTemplateId {
159
- final templateId = _env['OTP_TEMPLATE_ID' ];
160
- if (templateId == null || templateId.isEmpty) {
161
- _log.severe ('OTP_TEMPLATE_ID not found in environment variables.' );
162
- throw StateError (
163
- 'FATAL: OTP_TEMPLATE_ID environment variable is not set.' ,
164
- );
165
- }
166
- return templateId;
167
- }
132
+ static String get otpTemplateId => _getRequiredEnv ('OTP_TEMPLATE_ID' );
168
133
169
134
/// Retrieves the SendGrid API URL from the environment, if provided.
170
135
///
0 commit comments