fix: templates not being used for custom smtp#2865
Conversation
Console (appwrite/console)Project ID: Tip GraphQL API works alongside REST and WebSocket protocols |
WalkthroughThis PR renames four enum members used as email template keys (EmailTemplateType.Magicsession → EmailTemplateType.MagicSession, EmailTemplateType.Otpsession → EmailTemplateType.OtpSession, EmailTemplateType.Mfachallenge → EmailTemplateType.MfaChallenge, EmailTemplateType.Sessionalert → EmailTemplateType.SessionAlert) and updates their usages across email template components. It also updates package.json: bumps the Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes 🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/routes/`(console)/project-[region]-[project]/auth/templates/store.ts:
- Line 54: Add a brief TODO comment on each of the four lines that use string
assertions for EmailTemplateType—specifically the keys "'magicSession' as
EmailTemplateType", "'otpSession' as EmailTemplateType", "'mfaChallenge' as
EmailTemplateType", and "'sessionAlert' as EmailTemplateType"—explaining this is
a temporary workaround because the `@appwrite.io/console` SDK enum members (e.g.,
Magicsession, Otpsession, Mfachallenge, Sessionalert) use all-lowercase values
that don't match the API's camelCase template names, that the type assertion
bypasses type safety, and that the TODO should be removed once the SDK enum is
corrected.
| }, | ||
| { | ||
| key: EmailTemplateType.Magicsession, | ||
| key: 'magicSession' as EmailTemplateType, |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
# Find the EmailTemplateType enum definition in the installed package
find node_modules -name "*.d.ts" -o -name "*.ts" 2>/dev/null | head -20Repository: appwrite/console
Length of output: 3816
🏁 Script executed:
# Search for EmailTemplateType enum definition
rg "enum EmailTemplateType|export.*EmailTemplateType" --type ts --type js -A 15Repository: appwrite/console
Length of output: 42
🏁 Script executed:
# Look at the file context to understand the usage
head -100 src/routes/\(console\)/project-\[region\]-\[project\]/auth/templates/store.ts | tail -60Repository: appwrite/console
Length of output: 1872
🏁 Script executed:
# Check if the file imports EmailTemplateType and how it's used
grep -n "EmailTemplateType\|import.*Email" "src/routes/(console)/project-[region]-[project]/auth/templates/store.ts"Repository: appwrite/console
Length of output: 978
🏁 Script executed:
find node_modules -path "*@appwrite.io/console*" -name "*.d.ts" -o -path "*@appwrite.io/console*" -name "*.ts" 2>/dev/null | grep -v ".test\|.spec" | head -20Repository: appwrite/console
Length of output: 42
🏁 Script executed:
find node_modules -path "*@appwrite.io/console*" -type f \( -name "*.d.ts" -o -name "*.js" \) 2>/dev/null | head -30Repository: appwrite/console
Length of output: 42
🏁 Script executed:
rg "enum EmailTemplateType|export.*EmailTemplateType" node_modules/@appwrite.io/console -A 20 2>/dev/nullRepository: appwrite/console
Length of output: 42
🏁 Script executed:
rg "EmailTemplateType" node_modules 2>/dev/null | head -20Repository: appwrite/console
Length of output: 42
🏁 Script executed:
find node_modules -type f -name "*.d.ts" | xargs grep -l "EmailTemplateType" 2>/dev/null | head -10Repository: appwrite/console
Length of output: 42
🏁 Script executed:
ls -la node_modules/@appwrite.io/ 2>/dev/null || ls -la node_modules/ | grep appwriteRepository: appwrite/console
Length of output: 614
🏁 Script executed:
rg "EmailTemplateType" --type ts --type js -B 2 -A 10 | head -100Repository: appwrite/console
Length of output: 6429
🏁 Script executed:
find src -type f \( -name "*.ts" -o -name "*.d.ts" \) | xargs grep -l "enum EmailTemplateType\|export.*EmailTemplateType" 2>/dev/nullRepository: appwrite/console
Length of output: 44
🏁 Script executed:
cat package.json | grep -A 5 -B 5 "@appwrite.io/console"Repository: appwrite/console
Length of output: 639
🏁 Script executed:
find src -type f \( -name "*.ts" -o -name "*.d.ts" \) | xargs grep -l "enum.*EmailTemplateType\|export.*EmailTemplateType.*=" 2>/dev/nullRepository: appwrite/console
Length of output: 44
🏁 Script executed:
rg "enum EmailTemplateType|EmailTemplateType\s*=" --type ts --type tsx -B 2 -A 15Repository: appwrite/console
Length of output: 87
🏁 Script executed:
# Check if there's a types or lib folder
find . -maxdepth 3 -type d -name "types" -o -name "lib" -o -name "@appwrite.io" 2>/dev/null | grep -v node_modulesRepository: appwrite/console
Length of output: 69
🏁 Script executed:
# Look at git history to understand what changed
git log --oneline -20 -- "src/routes/(console)/project-[region]-[project]/auth/templates/store.ts" 2>/dev/nullRepository: appwrite/console
Length of output: 115
🏁 Script executed:
git show 1405f4231 -- "src/routes/(console)/project-[region]-[project]/auth/templates/store.ts" 2>/dev/null | head -100Repository: appwrite/console
Length of output: 3475
🏁 Script executed:
# Look in src/lib for type definitions
find src/lib -type f \( -name "*.ts" -o -name "*.d.ts" \) | head -20Repository: appwrite/console
Length of output: 782
🌐 Web query:
@appwrite.io/console EmailTemplateType enum members
💡 Result:
In Appwrite, the email template types (exposed as EmailTemplateType in the Console SDK @appwrite.io/console) correspond to these built-in template categories:
- Account verification
- Magic URL authentication
- Password reset
- User invite (appwrite.io)
Citations:
🌐 Web query:
appwrite console SDK EmailTemplateType magicSession otpSession
💡 Result:
In the Appwrite Console SDK (@appwrite.io/console), the EmailTemplateType enum uses Magicsession and Otpsession (not magicSession / otpSession) and they map to these string values: "magicsession" and "otpsession". [1]
import { EmailTemplateType } from '@appwrite.io/console';
EmailTemplateType.Magicsession; // "magicsession"
EmailTemplateType.Otpsession; // "otpsession"These correspond to the email templates used for Magic URL login and Email OTP login flows in Appwrite. [2][3]
Sources
[1] Appwrite Console SDK types: email-template-type.d.ts (jsDelivr)
[2] Appwrite Docs: Email OTP
[3] Appwrite Docs: Message templates / email templates
Add TODO comments documenting the enum value mismatch workaround.
The four changed keys use '...' as EmailTemplateType type assertions because the @appwrite.io/console SDK's enum members (Magicsession, Otpsession, Mfachallenge, Sessionalert) hold all-lowercase string values ("magicsession", "otpsession", etc.), which don't match the camelCase strings the API expects ("magicSession", "otpSession", etc.). Using as EmailTemplateType bypasses type safety—if the SDK is ever updated with correct enum members, this code won't be caught by the type system.
Add // TODO comments to each of the four lines (54, 60, 78, 84) explaining the workaround, following the guideline to comment complex logic. Example:
- key: 'magicSession' as EmailTemplateType,
+ // TODO: Use EmailTemplateType.MagicSession once SDK enum is corrected
+ key: 'magicSession' as EmailTemplateType,The inconsistency of mixing three direct enum references (Verification, Recovery, Invitation) with four string literal assertions should be resolved once the SDK is fixed.
Also applies to: 60-60, 78-78, 84-84
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@src/routes/`(console)/project-[region]-[project]/auth/templates/store.ts at
line 54, Add a brief TODO comment on each of the four lines that use string
assertions for EmailTemplateType—specifically the keys "'magicSession' as
EmailTemplateType", "'otpSession' as EmailTemplateType", "'mfaChallenge' as
EmailTemplateType", and "'sessionAlert' as EmailTemplateType"—explaining this is
a temporary workaround because the `@appwrite.io/console` SDK enum members (e.g.,
Magicsession, Otpsession, Mfachallenge, Sessionalert) use all-lowercase values
that don't match the API's camelCase template names, that the type assertion
bypasses type safety, and that the TODO should be removed once the SDK enum is
corrected.
|
Caution Failed to replace (edit) comment. This is likely due to insufficient permissions or the comment being deleted. Error details |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/routes/(console)/project-[region]-[project]/auth/templates/emailSessionAlertTemplate.svelte (1)
52-53:⚠️ Potential issue | 🟡 MinorPre-existing: truncated
valueprops missing closing}}.Both
Idcomponent instances pass incomplete placeholder strings asvalue:value={'{{ipAddress'} // should be '{{ipAddress}}' value={'{{country'} // should be '{{country}}'The slot content renders correctly, but any feature of
Idthat readsvalue(e.g., copy-to-clipboard) will receive a malformed placeholder. This predates this PR but is present in the file context.🐛 Proposed fix
- <Id value={'{{ipAddress'}>{'{{ipAddress}}'}</Id> - <Id value={'{{country'}>{'{{country}}'}</Id> + <Id value={'{{ipAddress}}'>{'{{ipAddress}}'}</Id> + <Id value={'{{country}}'>{'{{country}}'}</Id>🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/routes/`(console)/project-[region]-[project]/auth/templates/emailSessionAlertTemplate.svelte around lines 52 - 53, The Id component instances are passing truncated placeholder strings in their value props (value={'{{ipAddress'} and value={'{{country'}); update these to the correct placeholders by adding the missing closing braces so they read value={'{{ipAddress}}'} and value={'{{country}}'} respectively, ensuring any logic that reads Id.value (e.g., copy-to-clipboard) receives the full placeholder; locate the two Id usages in emailSessionAlertTemplate.svelte and correct their value props accordingly.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In
`@src/routes/`(console)/project-[region]-[project]/auth/templates/emailSessionAlertTemplate.svelte:
- Around line 52-53: The Id component instances are passing truncated
placeholder strings in their value props (value={'{{ipAddress'} and
value={'{{country'}); update these to the correct placeholders by adding the
missing closing braces so they read value={'{{ipAddress}}'} and
value={'{{country}}'} respectively, ensuring any logic that reads Id.value
(e.g., copy-to-clipboard) receives the full placeholder; locate the two Id
usages in emailSessionAlertTemplate.svelte and correct their value props
accordingly.

What does this PR do?
(Provide a description of what this PR does.)
Test Plan
Related PRs and Issues
(If this PR is related to any other PR or resolves any issue or related to any issue link all related PR and issues here.)
Have you read the Contributing Guidelines on issues?
(Write your answer here.)
Summary by CodeRabbit
Refactor
Chores