Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(providers): Add Postmark email provider (#10512)
- Loading branch information
1 parent
5b8bb9c
commit c97431b
Showing
1 changed file
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import type { EmailConfig, EmailUserConfig } from "./index.js" | ||
import { html, text } from "../lib/utils/email.js" | ||
|
||
/** @todo Document this */ | ||
export default function Postmark(config: EmailUserConfig): EmailConfig { | ||
return { | ||
id: "postmark", | ||
type: "email", | ||
name: "Postmark", | ||
from: "Auth.js <no-reply@authjs.dev>", | ||
maxAge: 24 * 60 * 60, | ||
async sendVerificationRequest(params) { | ||
const { identifier: to, provider, url, theme } = params | ||
const { host } = new URL(url) | ||
if (!provider.apiKey) throw new TypeError("Missing Postmark API Key") | ||
const res = await fetch("https://api.postmarkapp.com/email", { | ||
method: "POST", | ||
headers: { | ||
Accept: "application/json", | ||
"Content-Type": "application/json", | ||
"X-Postmark-Server-Token": provider.apiKey, | ||
}, | ||
body: JSON.stringify({ | ||
From: provider.from, | ||
To: to, | ||
Subject: `Sign in to ${host}`, | ||
TextBody: text({ url, host }), | ||
HtmlBody: html({ url, host, theme }), | ||
MessageStream: "outbound", | ||
}), | ||
}) | ||
|
||
if (!res.ok) | ||
throw new Error("Postmark error: " + JSON.stringify(await res.json())) | ||
}, | ||
options: config, | ||
} | ||
} |