Reader sign-in
Digize doesn’t host your newsletter’s website, so your own site signs readers in through the API. A reader signs in with their email; they get a link back to your site; your site turns it into a reader token that unlocks paid posts while their tier lasts.
The flow
Section titled “The flow”- On your site, the reader types their email. Your site’s server calls
POST /api/v1/newsletter/readers/sign-inwith theemail, thereturnUrlto come back to, and the visitor’sip. - Digize emails them a Sign in link from your newsletter’s sending address:
returnUrlwith?nl_token=…. The answer is{ sent: true }whether or not the email reads your newsletter, so nobody learns who does. - The link comes back to your site. Your server calls
POST /api/v1/newsletter/readers/verifywith thatnl_token, and gets a reader token and the reader:contactId,email,name,tierId,tierName,tier(freeorpaid) andexpiresAt. - Keep the reader token in a cookie (
HttpOnly,Secure, 30 days) and pass it asreadertoGET /api/v1/newsletter/publishedandGET /api/v1/newsletter/published/{slug}. A paid reader’s posts come whole; a free reader’s stop at the paywall, with the upgrade link in it.
import { createApiClient } from "@digize/sdk/api";
const api = createApiClient({ apiKey: env.DIGIZE_API_KEY });
// The sign-in form's handler.await api.newsletter.readers.signIn({ email: form.get("email"), returnUrl: "https://example.com/account/signed-in", ip: request.headers.get("cf-connecting-ip") ?? undefined,});
// /account/signed-in?nl_token=…const { token, reader } = await api.newsletter.readers.verify({ token: url.searchParams.get("nl_token"),});// Set-Cookie: reader=<token>; HttpOnly; Secure; SameSite=Lax; Max-Age=2592000
// A post's page.const post = await api.newsletter.posts.bySlug({ slug, reader: cookies.get("reader"),});What keeps it safe
Section titled “What keeps it safe”- Only your sites.
returnUrlmust behttps(orhttponlocalhost) on a host Newsletter › Settings › Paid allows: the post URL pattern’s site, the address readers land on after paying, and any you list there. - A link works once, for 30 minutes. A few links an hour per email at most, and a limit per visitor when you pass
ip. - The tier is read again on every use. The token says who the reader is; whether they’re paid is checked each time, so a reader who cancels loses paid posts at once, and one who upgrades gets them without signing in again.
- A reader token works for 30 days, for its own workspace only.
POST /api/v1/newsletter/readers/mesays who a token is for now, ornullonce it has expired.
Upgrading from your site
Section titled “Upgrading from your site”A free reader’s paywall carries the upgrade link to the upgrade page. A site with its own upgrade page can start Checkout itself with POST /api/v1/newsletter/tiers/{id}/checkout (the reader token or an email, the tier and month or year), and a gift with POST /api/v1/newsletter/gifts/checkout.