Email notifications: settings UI + mail adapter #4
1 changed files with 14 additions and 3 deletions
|
|
@ -99,9 +99,18 @@ export class MailNotifications {
|
|||
throw new Error("Email notification server not configured")
|
||||
}
|
||||
|
||||
const body = {email, frequency}
|
||||
const bodyJson = JSON.stringify(body)
|
||||
|
||||
let authEvent
|
||||
try {
|
||||
authEvent = await $signer.sign(await makeHttpAuth(EMAIL_NOTIFICATION_SERVER, "PUT"))
|
||||
authEvent = await $signer.sign(
|
||||
await makeHttpAuth(
|
||||
buildUrl(EMAIL_NOTIFICATION_SERVER, "subscription", "email"),
|
||||
"PUT",
|
||||
bodyJson,
|
||||
),
|
||||
)
|
||||
} catch (e) {
|
||||
emailNotificationState.set({
|
||||
error: "Failed to create authentication. Check your signer.",
|
||||
|
|
@ -115,7 +124,7 @@ export class MailNotifications {
|
|||
try {
|
||||
res = await fetch(buildUrl(EMAIL_NOTIFICATION_SERVER, "subscription", "email"), {
|
||||
method: "PUT",
|
||||
body: JSON.stringify({email, frequency, pubkey: $user.pubkey}),
|
||||
body: bodyJson,
|
||||
headers: {Authorization: authHeader, "Content-Type": "application/json"},
|
||||
})
|
||||
} catch (e) {
|
||||
|
|
@ -149,7 +158,9 @@ export class MailNotifications {
|
|||
if (!$signer) return
|
||||
|
||||
try {
|
||||
const authEvent = await $signer.sign(await makeHttpAuth(EMAIL_NOTIFICATION_SERVER, "DELETE"))
|
||||
const authEvent = await $signer.sign(
|
||||
await makeHttpAuth(buildUrl(EMAIL_NOTIFICATION_SERVER, "subscription", key), "DELETE"),
|
||||
)
|
||||
const authHeader = makeHttpAuthHeader(authEvent)
|
||||
|
||||
await fetch(buildUrl(EMAIL_NOTIFICATION_SERVER, "subscription", key), {
|
||||
|
|
|
|||
Loading…
Reference in a new issue