Skip to content

Instantly share code, notes, and snippets.

@davidystephenson
Created March 18, 2026 03:05
Show Gist options
  • Select an option

  • Save davidystephenson/7d1d58b6cd64a064ab7e2e67ac705aa7 to your computer and use it in GitHub Desktop.

Select an option

Save davidystephenson/7d1d58b6cd64a064ab7e2e67ac705aa7 to your computer and use it in GitHub Desktop.

One-Time Secret Link

Build a small app where a user can create a secret message and get a link to share. When someone opens the link, they can read the message once, and then it’s gone.

Data Storage

store data in memory using an array.

  • Create a file like lib/store.ts
  • Export an array to hold secrets

Each item in the array should look like: { id: string, text: string, createdAt: number }

This runs on the server, so the data will persist while the dev server is running. Of course data resets on server restart without a DB.

API Routes

POST /api/secret

  • Validate request body contains text.
  • Generate a random id (string)
  • Store using in array with push
  • Respond with { "id": "abc123" }

GET /api/secret/[id]

  • Find the message in the array with find.
  • If it exists:
    • return it
    • remove it using from the array with filter
  • If not:
    • return a 404 status

UI Pages

/

  • Form with input field
  • “Create secret link” submit button
  • On submit:
    • POST message
    • show generated link like localhost:3000/secret/${id}

/secret/[id]

  • Fetch message
  • Show message if found
  • If not show “Not Found”

Focus on getting it working, don't worry about styling.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment