@@ -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 ///
@@ -124,4 +123,51 @@ abstract final class EnvironmentConfig {
124123 final hours = int .tryParse (_env['JWT_EXPIRY_HOURS' ] ?? '1' );
125124 return Duration (hours: hours ?? 1 );
126125 }
126+
127+ /// Retrieves the SendGrid API key from the environment.
128+ ///
129+ /// 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+ }
140+
141+ /// Retrieves the default sender email from the environment.
142+ ///
143+ /// 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+ }
154+
155+ /// Retrieves the SendGrid OTP template ID from the environment.
156+ ///
157+ /// 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+ }
168+
169+ /// Retrieves the SendGrid API URL from the environment, if provided.
170+ ///
171+ /// Returns `null` if the `SENDGRID_API_URL` is not set.
172+ static String ? get sendGridApiUrl => _env['SENDGRID_API_URL' ];
127173}
0 commit comments