---
title: "Part 5: notify and share"
description: "Email people when their strip is ready, show the in-app inbox, and share a finished strip by a link anyone can open."
canonical_url: "https://nuxt-backend.dev/docs/start/tutorial/notify-and-share"
---
# Part 5: notify and share

> Email people when their strip is ready, show the in-app inbox, and share a finished strip by a link anyone can open.

Version: nuxt-backend 0.6.x · Tab: Start · Kind: tutorial · Status: stable

Every page: [llms.txt](https://nuxt-backend.dev/llms.txt) · Skill for coding agents: [nuxt-backend](https://nuxt-backend.dev/.well-known/skills/nuxt-backend/SKILL.md)

Commands use npm; use your project's package manager.

Tell people when their strip is ready, in the app, by email and as a push, each a channel they choose, and let them share a finished strip by link.

<table>
<thead>
  <tr>
    <th>
      Part
    </th>
    
    <th>
      You add
    </th>
    
    <th>
      Accounts
    </th>
    
    <th>
      Time
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      5. Notify and share
    </td>
    
    <td>
      A "strip ready" notification in the inbox, by email and as a push, the channels to choose, who else is looking at a strip, and share links with a public page
    </td>
    
    <td>
      A Resend account
    </td>
    
    <td>
      20 min
    </td>
  </tr>
</tbody>
</table>

## Before you start

You need the app from [Part 4](https://nuxt-backend.dev/docs/start/tutorial/generate). This part adds a Resend account: sign up at [resend.com](https://resend.com) and create an API key. In development, Resend stays in test mode. It delivers only to its test addresses, such as `delivered@resend.dev`, and still sends real delivery events. Put the key and a sender in `.env.local`:

```bash [.env.local]
EMAIL_API_KEY=re_your_api_key
EMAIL_FROM="Panels <onboarding@resend.dev>"
```

Then push them:

```bash
npx nuxt-backend env push
```

[Resend](https://nuxt-backend.dev/docs/services/resend) covers the sending domain, the region and the separate subdomains for product and marketing mail you set up before launch.

<steps level="3">

### Brand the emails

Give Panels' emails its brand. The package's own emails, sign-in codes and receipts included, use the same layout. Change the `setupEmail` call in `backend/email.ts`; the logo is `public/email-logo.png`:

```ts [backend/email.ts]
export const email = setupEmail(components, {
  paths,
  brand: {
    name: 'Panels',
    logo: '/email-logo.png',
    address: 'Panels, 1 Example Street, 10115 Berlin, Germany',
  },
  theme: {
    colors: { background: '#f6f1e7', card: '#ffffff', text: '#1d1b16', accent: '#e4572e', accentText: '#ffffff' },
  },
  topics: {
    productNews: {
      name: 'Product news',
      description: 'New styles and features, about once a month.',
      subscribedByDefault: false,
    },
  },
  // The languages Panels' emails are written in, by each account's own:
  // the package's translations, as the site runs without @nuxtjs/i18n.
  // Named, so messages for one language never narrow the others to English.
  locales: ['en', 'de', 'es', 'fr', 'ru'],
  // The labels app.config.ts sets (labels.generated.ts, which the module
  // rewrites from it): the words of Panels' own notification (notifications.ts)
  // and its refusals, so its email and its push say what the inbox says.
  labels,
})
```

Keep every export below the call as the starter wrote it: the preference center, the announcements, the suppressions and `send` all read them. The brand replaces the starter's `brand.generated.ts` import, which you can remove. Keep its `labels.generated.ts` import: `labels` carries the words app config gives the "strip ready" notification, which the next step sends by email and as a push. `locales` names the languages an email may be written in, the reader's own when it is one of them: without it, the languages `messages` carries, so a file of English messages alone would write every email in English ([Send email in each reader's language](https://nuxt-backend.dev/docs/build/email/templates/languages)).

Now that `email.ts` declares its topics, create them at Resend, with the webhook subscription:

```bash
npx nuxt-backend email sync
```

### Announce a finished strip

Notifications derive from backend events. Record one when a strip is ready, and the package turns it into a notification on every channel its kind allows and the author left on. Add the helper to `backend/strips.ts`, with its import:

```ts [backend/strips.ts]
import { audit } from './audit'
// …
async function announceReady(ctx: MutationCtx, strip: Doc<'strips'>) {
  await audit.recordBackendEvent(ctx, {
    type: 'app.strip_ready',
    subjectId: strip.authorId,
    entityId: strip.workspaceId,
    targetId: strip._id,
  })
}
```

Call it where Part 4 left a gap: after the last panel in `savePanel`, and after a canned strip's copy in `generate`. `savePanel` saves each panel once, so the strip is announced once:

```ts [backend/strips.ts]
await ctx.db.patch('strips', stripId, { panels: [...strip.panels, { imageId, caption }], status: last ? 'ready' : 'queued' })
    if (last) await announceReady(ctx, strip)
// …
      await ctx.db.patch('strips', id, { panels: canned, cached: true, status: 'ready' })
      await announceReady(ctx, strip)
      return
```

Every event the package records about a person already reaches the inbox; an event of your own joins through `notify`, which says what it becomes and where it links. Add it to the starter's `setupNotifications` call in `backend/notifications.ts`:

```ts [backend/notifications.ts]
import { routes } from './routes'
// …
export const notifications = setupNotifications(components, {
  email,
  paths,
  notify: {
    'app.strip_ready': {
      channels: ['app', 'email', 'push'],
      link: event => routes.strip(event.targetId ?? ''),
    },
  },
})
// …
```

Keep `email`, `paths` and every export below the call as the starter wrote them. `backend/audit.ts` already passes `notifications` to `setupAudit`, so the event you recorded reaches it. Each channel is one the author can turn off:

- `app` puts it in the inbox, behind the bell.
- `email` sends it through the `email` instance, in Panels' brand, with the words app config gives it and a button to the link. It is not transactional mail: the weekly cap and the quiet hours hold it as they hold every notification email.
- `push` sends a web push to each device that allowed it; `npx nuxt-backend env push` generates the `PUSH_PUBLIC_KEY` and `PUSH_PRIVATE_KEY` it needs.

A notification's words are labels. Panels speaks one language, so it writes them once in app config: the module copies them to `backend/labels.generated.ts` on the next `dev`, and the email and the push read them from there ([Labels reach the backend](https://nuxt-backend.dev/docs/build/ui/customize/labels#labels-reach-the-backend)). An app in several languages gives them per language in its i18n messages instead ([One language or many](https://nuxt-backend.dev/docs/build/ui/customize/labels#one-language-or-many)):

```ts [app/app.config.ts]
labels: {
      notifications: {
        strip_ready: { title: 'Your strip is ready', body: 'Open it to read and share it.' },
      },
```

`<AppShell>` already shows the bell with the inbox and its unread count, so the layout needs no inbox of its own. Give people a page to choose their channels instead, and link it from the header. This is the finished layout:

```vue [app/layouts/default.vue]
<script setup lang="ts">
const pricing = useBackendPagePath('pricing')
const { isSignedIn } = useAuth()
const credits = useCredits({ meter: 'credits' })
</script>

<template>
  <AppShell switcher>
    <template #brand>
      <NuxtLink :to="{ name: 'strips' }">
        Panels
      </NuxtLink>
    </template>
    <template #nav>
      <NuxtLink :to="{ name: 'strips' }">
        Strips
      </NuxtLink>
      <NuxtLink
        v-if="pricing"
        :to="pricing"
      >
        Credits
      </NuxtLink>
      <NuxtLink :to="{ name: 'notifications' }">
        Notifications
      </NuxtLink>
    </template>
    <template #actions>
      <NuxtLink
        v-if="pricing && isSignedIn"
        :to="pricing"
      >
        {{ credits.balance.value ?? '…' }} credits
      </NuxtLink>
    </template>
    <slot />
  </AppShell>
</template>
```

```vue [app/pages/notifications.vue]
<script setup lang="ts">
definePageMeta({ auth: true })
</script>

<template>
  <div class="page">
    <h1>Notifications</h1>
    <NotifyChannels />
  </div>
</template>
```

`useEmailPreferences` reads each person's channels for every kind, live, and `usePushSubscription` asks the browser for web push:

```vue [app/components/NotifyChannels.vue]
<script setup lang="ts">
const { channels, set, isPending, error } = useEmailPreferences()
const push = usePushSubscription()

const KIND = 'app.strip_ready'
const names: Record<string, string> = { app: 'In the app', email: 'By email', push: 'On this device' }
const ready = computed(() => channels.value.find(choice => choice.type === KIND))
</script>
<!-- … -->
```

The rest of the component, in the template, is a checkbox per channel, **In the app**, **By email** and **On this device**, and a button that turns push on or off on this device.

**You should see** the bell's unread count go up when a strip finishes. To read the email, sign in as `delivered+panels@resend.dev`, draw a strip, then run `npx nuxt-backend inbox delivered+panels@resend.dev`. Turn **By email** off on `/notifications` and draw another: the inbox gets it, and no email goes out.

### Show who else is looking

A strip page can list who else in the workspace has it open, as they come and go. Convex's presence component keeps the rooms, and the package puts them behind the sign-in. Install it and mount it beside the other components:

```bash
pnpm add @convex-dev/presence
```

```ts [backend/convex.config.ts]
import presence from '@convex-dev/presence/convex.config'
// …
app.use(presence)
```

Each strip is a room, `strip:<id>`. `canJoin` runs on every heartbeat, and lets in the members of the strip's workspace only, the same people who may open it. It reads the membership fresh from the member table, as `workspace` functions do, because a removed member's sign-in can still name the workspace for a while. A heartbeat never takes anyone out, so `leaveWorkspace` does that for a member who loses access:

```ts [backend/presence.ts]
import { setupPresence } from 'nuxt-backend/presence'
import { v } from 'convex/values'
import { components } from './_generated/api'
import { internalMutation } from './_generated/server'

// Who else has a strip open, live (app/components/StripViewers.vue). A
// strip's room is `strip:<id>`, and it lets in the members of the strip's
// workspace only: the same people who may open the strip. Membership is read
// fresh from the member table, as `workspace` functions read it, because a
// removed member's sign-in can still name the workspace for a while.
export const { list, heartbeat, disconnect, presence } = setupPresence(components, {
  canJoin: async ({ roomId, userId, claims }, ctx) => {
    const id = roomId.startsWith('strip:') ? ctx.db.normalizeId('strips', roomId.slice('strip:'.length)) : null
    const strip = id ? await ctx.db.get(id) : null
    if (strip === null || strip.hidden || strip.workspaceId !== claims.activeOrganizationId) return false
    const member = await ctx.runQuery(components.backend.adapter.findOne, {
      model: 'member',
      where: [{ field: 'organizationId', value: String(strip.workspaceId) }, { field: 'userId', value: userId }],
    })
    return member !== null
  },
})

// A heartbeat lets people in but never takes them out, so the mutations that
// take access away do: hiding a strip empties its room (admin.ts), and a
// member removed from a workspace leaves its strips' rooms (auth.ts).
export const leaveWorkspace = internalMutation({
  args: { workspaceId: v.string(), userId: v.string() },
  handler: async (ctx, { workspaceId, userId }) => {
    // The rooms the account was in, offline ones too, up to a thousand (the
    // component reads 104 by default).
    for (const { roomId } of await presence.listUser(ctx, userId, false, 1_000)) {
      const id = roomId.startsWith('strip:') ? ctx.db.normalizeId('strips', roomId.slice('strip:'.length)) : null
      const strip = id ? await ctx.db.get(id) : null
      if (strip?.workspaceId === workspaceId) await presence.removeRoomUser(ctx, roomId, userId)
    }
  },
})
```

Two mutations take access away, and each empties what it closes. Hiding a strip (Part 3's `hide`) removes its room:

```ts [backend/admin.ts]
import { presence } from './presence'
// …
    hide: async (ctx, { table, id }) => {
      if (table !== 'strips') return
      await ctx.db.patch('strips', id, { hidden: true })
      // Nobody may open a hidden strip, so nobody is still looking at it.
      await presence.removeRoom(ctx, `strip:${id}`)
    },
```

And removing a member from a workspace takes them out of its strips' rooms, from the workspace hook in `backend/auth.ts`:

```ts [backend/auth.ts]
workspaces: {
    // …
    onMemberRemoved: async (ctx, { workspace, userId }) => {
      await ctx.runMutation(internal.presence.leaveWorkspace, { workspaceId: workspace.id, userId })
    },
  },
```

`useRoomPresence` keeps the signed-in person in the room while the page is open and visible, and `others` is who else is there:

```vue [app/components/StripViewers.vue]
<script setup lang="ts">
// Who else in the workspace has this strip open, as they come and go
// (backend/presence.ts). The status line stays mounted, so a screen reader
// hears who arrives; it is empty while the reader is alone.
const props = defineProps<{ stripId: string }>()
const { others } = useRoomPresence(() => `strip:${props.stripId}`)
</script>

<template>
  <p
    role="status"
    class="muted"
  >
    <template v-if="others.length">
      Also looking: {{ others.map(person => person.name ?? 'Someone').join(', ') }}
    </template>
  </p>
</template>
```

It goes on the strip's page, under the drawing: the finished page at the end of this part shows where.

**You should see** nothing while you are alone on a strip. Open the same strip as another member of the workspace, in a second browser: each page says the other is also looking, and the line goes away a moment after one of them closes the tab.

### Share a strip by link

A share link is a long random token in a URL. Anyone with it can read the strip, without an account, until the author turns the link off. Declare the strips table shareable in `backend/storage.ts`, in the gap Part 3 left, with its imports:

```ts [backend/storage.ts]
import { isDemo } from './demo'
import { routes } from './routes'
// …
storage.shareable('strips', {
  path: routes.share,
  canShare: (ctx, strip) => !isDemo() && strip.authorId === ctx.user.id && strip.status === 'ready',
})
```

The public demo shares nothing: a link there would publish whatever anyone drew.

The public page reads the strip by its token. `storage.resolveShareLink` returns `{ id, sharedBy, ogImageUrl }`, or `null` for a token that no longer works. Add the query to `backend/strips.ts`. It runs without a signed-in user, and returns only what the page shows:

```ts [backend/strips.ts]
export const shared = query({
  args: { token: v.string() },
  handler: async (ctx, { token }) => {
    const link = await storage.resolveShareLink(ctx, 'strips', token)
    const id = link && ctx.db.normalizeId('strips', link.id)
    const strip = id ? await ctx.db.get('strips', id) : null
    if (!strip || strip.status !== 'ready' || strip.hidden) return null
    const panels = await withUrls(ctx, strip.panels)
    return { idea: strip.idea, panels: panels.map(({ caption, url }) => ({ caption, url })) }
  },
})
```

`useShareLink` turns the link on and off from the strip's page. On the demo, the component says where to run Panels that shares:

```vue [app/components/ShareStrip.vue]
<script setup lang="ts">
import { api } from '#backend/api'

const props = defineProps<{ stripId: string }>()
const demo = useQuery(api.demo.status, {})
const { shared, url, enable, revoke, isPending, error } = useShareLink('strips', () => props.stripId)
</script>

<template>
  <section aria-labelledby="share-heading">
    <h2 id="share-heading">
      Share
    </h2>
    <p v-if="demo && !demo.sharing">
      Sharing is off on the public demo.
      <a :href="demo.templateUrl">Run Panels yourself</a> to share strips by a link.
    </p>
    <template v-else-if="demo">
      <p v-if="url">
        Anyone with this link can read the strip: <code>{{ url }}</code>
      </p>
      <div class="row">
        <button
          type="button"
          :aria-disabled="isPending || undefined"
          @click="isPending || enable()"
        >
          {{ shared ? 'Make a new link' : 'Turn on a link' }}
        </button>
        <button
          v-if="shared"
          type="button"
          :aria-disabled="isPending || undefined"
          @click="isPending || revoke()"
        >
          Turn the link off
        </button>
      </div>
      <p
        v-if="error"
        role="alert"
      >
        {{ error.message }}
      </p>
    </template>
  </section>
</template>
```

The page at the link reads the strip on the server, so the first HTML already holds it. It keeps itself out of search results, and the token out of the `Referer` header of every link it holds:

```vue [app/pages/s/[token].vue]
<script setup lang="ts">
import { api } from '#backend/api'

const route = useRoute()
const { data: strip } = await useAsyncQuery(api.strips.shared, { token: route.params.token as string })
useSeoMeta({ title: () => strip.value?.idea ?? 'Panels', robots: 'noindex', referrer: 'no-referrer' })
</script>

<template>
  <div class="page">
    <article v-if="strip">
      <h1>{{ strip.idea }}</h1>
      <figure
        v-for="panel in strip.panels"
        :key="panel.caption"
      >
        <img
          v-if="panel.url"
          :src="panel.url"
          :alt="panel.caption"
          width="480"
        >
        <figcaption>{{ panel.caption }}</figcaption>
      </figure>
      <AiLabel />
    </article>
    <p v-else>
      This link no longer works. Ask the author for a new one.
    </p>
  </div>
</template>
```

Show the `ShareStrip` component on the strip's page once the strip is ready, and `StripViewers` under the drawing. This is the finished page:

```vue [app/pages/strips/[id].vue]
<script setup lang="ts">
import { api } from '#backend/api'
import type { Id } from '#backend/dataModel'

definePageMeta({ auth: true })

const route = useRoute()
const id = computed(() => route.params.id as Id<'strips'>)
const { isReady } = useAuth()
const strip = useQuery(api.strips.get, () => (isReady.value ? { id: id.value } : 'skip'))
const demo = useQuery(api.demo.status, {})
</script>

<template>
  <div
    v-if="strip"
    class="page"
  >
    <h1>{{ strip.idea }}</h1>
    <StripPhoto
      :strip-id="strip._id"
      :photo-id="strip.photoId"
    />
    <p
      v-if="demo?.demo && strip.ideaId"
      class="muted"
    >
      On the demo, this idea is copied from panels drawn once: a photo you add is not used.
    </p>
    <StripDrawing :strip="strip" />
    <ShareStrip
      v-if="strip.status === 'ready'"
      :strip-id="strip._id"
    />
    <StripViewers :strip-id="strip._id" />
    <ReportStrip :strip-id="strip._id" />
  </div>
  <div
    v-else-if="strip === null"
    class="page"
  >
    <p>This strip is not in your workspace.</p>
  </div>
</template>
```

On the demo, a strip from a canned idea is a copy of the panels drawn once, so the page says a photo plays no part in it.

**You should see** a link under a finished strip. Open it in a private window: the strip shows without a sign-in, with its label.

</steps>

## Check your work

- `npx nuxt-backend inbox delivered+panels@resend.dev` lists "Your strip is ready", sent to `delivered+panels@resend.dev`. The DevTools Email tab renders it in Panels' colours.
- The bell in the header shows the notification, and opening it takes you to the strip.
- Press **Turn the link off**, then reload the private window. The page says the link no longer works.

## What you used

- `setupEmail({ brand, theme, topics, messages })` ([Brand your emails](https://nuxt-backend.dev/docs/build/email/templates/theme)).
- `npx nuxt-backend email sync` and the dev inbox ([Read test mail in the dev inbox](https://nuxt-backend.dev/docs/develop/dev-inbox)).
- `setupNotifications({ notify })` with the `app`, `email` and `push` channels, and the shell's bell ([Show in-app notifications](https://nuxt-backend.dev/docs/build/email/notifications)), fed by your own event ([Notify people about your own events](https://nuxt-backend.dev/docs/build/email/notifications/custom-events)).
- `useEmailPreferences` and `usePushSubscription` ([Send web push notifications](https://nuxt-backend.dev/docs/build/email/notifications/web-push)).
- `setupPresence({ canJoin })` and `useRoomPresence` ([Show who is here](https://nuxt-backend.dev/docs/build/data/read-write/presence)).
- `storage.shareable`, `storage.resolveShareLink` and `useShareLink` ([Share by link](https://nuxt-backend.dev/docs/build/data/files/share-links)).

## Next

[Part 6: test and deploy](https://nuxt-backend.dev/docs/start/tutorial/deploy) tests the paid path, then puts Panels in production.


## Sitemap

See the full [sitemap](https://nuxt-backend.dev/sitemap.md) for all pages.
