fix email notifications: match mailship PUT API with full-URL NIP-98 and payload tag
All checks were successful
CI / lint-check-build (pull_request) Successful in 3m19s
All checks were successful
CI / lint-check-build (pull_request) Successful in 3m19s
- register(): sign makeHttpAuth with full URL (/subscription/email), method PUT, and serialized body so both u-tag and payload tag match mailship's verifyNip98Auth. Drop pubkey from request body (server reads it from the auth event). - unregister(): sign makeHttpAuth with full URL (/subscription/:key) and method DELETE, matching mailship's u-tag expectation. Closes PR #4
This commit is contained in:
parent
d6f0e47edf
commit
3981ed9608
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