-
Notifications
You must be signed in to change notification settings - Fork 0
fix(api): make OTP email sender configurable via env #69
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -17,8 +17,15 @@ impl EmailService { | |||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| pub async fn send_otp_email(&self, email: &str, otp: &str) -> Result<(), AppError> { | ||||||||||||||||||||||||||||||
| // Brevo only sends from verified senders, so the from-address must be | ||||||||||||||||||||||||||||||
| // configurable per deployment instead of a hardcoded domain. | ||||||||||||||||||||||||||||||
| let from_email = std::env::var("EMAIL_FROM") | ||||||||||||||||||||||||||||||
| .unwrap_or_else(|_| "no-reply@txio-backend.com".to_string()); | ||||||||||||||||||||||||||||||
| let from_name = | ||||||||||||||||||||||||||||||
| std::env::var("EMAIL_FROM_NAME").unwrap_or_else(|_| "txio Team".to_string()); | ||||||||||||||||||||||||||||||
|
Comment on lines
+22
to
+25
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Handle empty env values, not just missing ones. Current fallback only runs when the variable is absent. If Suggested patch- let from_email = std::env::var("EMAIL_FROM")
- .unwrap_or_else(|_| "no-reply@txio-backend.com".to_string());
- let from_name =
- std::env::var("EMAIL_FROM_NAME").unwrap_or_else(|_| "txio Team".to_string());
+ let from_email = std::env::var("EMAIL_FROM")
+ .ok()
+ .map(|v| v.trim().to_string())
+ .filter(|v| !v.is_empty())
+ .unwrap_or_else(|| "no-reply@txio-backend.com".to_string());
+ let from_name = std::env::var("EMAIL_FROM_NAME")
+ .ok()
+ .map(|v| v.trim().to_string())
+ .filter(|v| !v.is_empty())
+ .unwrap_or_else(|| "txio Team".to_string());📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| let body = json!({ | ||||||||||||||||||||||||||||||
| "sender": { "email": "no-reply@txio-backend.com", "name": "txio Team" }, | ||||||||||||||||||||||||||||||
| "sender": { "email": from_email, "name": from_name }, | ||||||||||||||||||||||||||||||
| "to": [{ "email": email }], | ||||||||||||||||||||||||||||||
| "subject": "Your txio OTP", | ||||||||||||||||||||||||||||||
| "htmlContent": format!("<p>Your verification code is: <strong>{}</strong></p><p>This code will expire in 10 minutes.</p>", otp) | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Quote
EMAIL_FROM_NAMEto avoid parser ambiguity.txio Teamcontains whitespace; quoting it avoids inconsistent parsing across dotenv loaders/shell-based setups.Suggested patch
📝 Committable suggestion
🧰 Tools
🪛 dotenv-linter (4.0.0)
[warning] 10-10: [UnorderedKey] The EMAIL_FROM_NAME key should go before the JWT_SECRET key
(UnorderedKey)
[warning] 10-10: [ValueWithoutQuotes] This value needs to be surrounded in quotes
(ValueWithoutQuotes)
🤖 Prompt for AI Agents
Source: Linters/SAST tools