O

ouhammmourachid / waitlist

Public

A production-ready PocketBase waitlist collection for collecting emails, assigning queue positions, tracking invitation status, and recording signup sources.

  • Auth
  • 0 deploys
  • 1 fork

Waitlist

A PocketBase waitlist for product launches: collect emails, assign queue positions, track invitations and signup sources, and send a branded confirmation email.

Features

  • Public signup form endpoint, with duplicate emails blocked
  • Queue position assigned automatically (#1, #2, #3...)
  • Status flow: pending → invited → converted
  • Confirmation email with the visitor's position, branded with your app name
  • Signup source tracking (landing_page, twitter, producthunt...)
  • Visitors can't read the list or set their own status or position

Fields

FieldTypeDescription
emailEmailUnique, stored lowercase
nameTextOptional, used in the confirmation email
phoneTextOptional
statusSelectpending, invited, converted
positionNumberQueue position, set by a hook
invited_atDateWhen you sent the invitation
sourceTextWhere the signup came from
createdAutodateCreation date
updatedAutodateLast update date

Rules

RuleValueMeaning
ListnullSuperusers only
ViewnullSuperusers only
Create""Anyone can join
UpdatenullSuperusers only (you, from the dashboard)
DeletenullSuperusers only

Setup

  • Settings > Application: set the app name and URL. The email uses both.
  • Settings > Mail settings: configure SMTP. Without SMTP, signups still work and no email is sent.

Usage

import PocketBase from "pocketbase"
const pb = new PocketBase("https://YOUR-INSTANCE.pocketshub.com")

const entry = await pb.collection("waitlist").create({
  email: "user@example.com",
  name: "Sam",
  source: "landing_page",
})
console.log(`You're #${entry.position} in line`)

Invite people from the dashboard by setting status to invited and invited_at to now.

Use cases

  • SaaS launches
  • Beta programs and early access
  • Product Hunt launches
  • Private invitations

License

MIT

waitlist
  • id
  • email
  • name
  • statussingle
  • phone
  • position
  • invited_at
  • source
  • created
  • updated

1 collection, 0 relations

main.pb.js81 lines
/// <reference path="../pb_data/types.d.ts" />

// Public signup: normalise the email, block duplicates, and keep status/position server-side.
onRecordCreateRequest((e) => {
  const email = e.record.getString("email").trim().toLowerCase()
  e.record.set("email", email)

  if (e.app.countRecords("waitlist", $dbx.hashExp({ email: email })) > 0) {
    throw new BadRequestError("This email is already on the waitlist.")
  }

  if (!e.hasSuperuserAuth()) {
    e.record.set("status", "pending")
    e.record.set("position", 0)
    e.record.set("invited_at", "")
  }
  e.next()
}, "waitlist")

// Assign the next queue position (highest + 1) right before the insert.
onRecordCreate((e) => {
  if (!e.record.getInt("position")) {
    const result = new DynamicModel({ max: 0 })
    e.app.db().newQuery("SELECT COALESCE(MAX(position), 0) AS max FROM waitlist").one(result)
    e.record.set("position", result.max + 1)
  }
  if (!e.record.getString("status")) e.record.set("status", "pending")
  e.next()
}, "waitlist")

// Confirmation email, branded with your app's name and URL (Settings > Application).
// Skipped when SMTP isn't configured; a failed email never blocks the signup.
onRecordAfterCreateSuccess((e) => {
  const settings = e.app.settings()
  if (settings.smtp.enabled) {
    const esc = (s) =>
      String(s).replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;")
    const appName = settings.meta.appName || "our"
    const appURL = settings.meta.appURL
    const name = e.record.getString("name")
    const position = e.record.getInt("position")

    const html = `
<!DOCTYPE html>
<html>
<body style="margin:0;padding:0;background-color:#f4f4f4;font-family:'Helvetica Neue',Arial,sans-serif;">
  <table width="100%" cellpadding="0" cellspacing="0" style="background-color:#f4f4f4;padding:40px 0;">
    <tr><td align="center">
      <table width="480" cellpadding="0" cellspacing="0" style="background-color:#ffffff;border-radius:12px;overflow:hidden;">
        <tr><td style="background-color:#0a0a0a;padding:32px 40px;text-align:center;">
          <div style="font-size:13px;letter-spacing:3px;color:#ffffff;text-transform:uppercase;font-weight:600;">${esc(appName)}</div>
        </td></tr>
        <tr><td style="padding:40px;">
          <h1 style="margin:0 0 16px 0;font-size:24px;line-height:1.3;color:#0a0a0a;">You're on the list${name ? ", " + esc(name) : ""}.</h1>
          <p style="margin:0 0 24px 0;font-size:15px;line-height:1.6;color:#4a4a4a;">
            Thanks for joining the ${esc(appName)} waitlist. You're currently
            <strong style="color:#0a0a0a;">#${position}</strong> in line. We'll email you when your spot opens up.
          </p>
          ${appURL ? `<a href="${esc(appURL)}" style="display:inline-block;background-color:#0a0a0a;color:#ffffff;text-decoration:none;font-size:14px;font-weight:600;padding:14px 28px;border-radius:6px;">Visit ${esc(appName)}</a>` : ""}
        </td></tr>
      </table>
    </td></tr>
  </table>
</body>
</html>`

    try {
      e.app.newMailClient().send(
        new MailerMessage({
          from: { address: settings.meta.senderAddress, name: settings.meta.senderName },
          to: [{ address: e.record.getString("email") }],
          subject: `You're on the ${appName} waitlist`,
          html: html,
        }),
      )
    } catch (err) {
      e.app.logger().error("Waitlist email failed", "record", e.record.id, "error", String(err))
    }
  }
  e.next()
}, "waitlist")