Email Service
The API server includes a flexible service for sending transactional emails, which are essential for user authentication flows like sending One-Time Passwords (OTPs).
Core Components
Section titled “Core Components”The email functionality is built on a clean, decoupled architecture:
-
EmailClient
Interface: This is an abstract class that defines the contract for any email-sending service. It requires a single method,sendTransactionalEmail
. -
EmailSendGrid
Implementation: The default implementation provided in the toolkit uses the SendGrid service. It handles the specifics of making API calls to SendGrid. -
EmailRepository
: This repository acts as a layer between the business logic and the email client. It abstracts away the specific client being used. -
AuthService
: The authentication service uses theEmailRepository
to trigger sending OTP emails during the sign-in process.
How it Works
Section titled “How it Works”When a user requests a sign-in code, the AuthService
calls the EmailRepository
, which in turn calls the configured EmailClient
(by default, EmailSendGrid
). This layered approach means the AuthService
doesn’t need to know or care about how the email is sent, only that it can be sent.