No description
Find a file
bananabas 67f24f4cd7 Fix: Improve better-auth integration and passkey flow
Adjusted the `BETTER_AUTH_URL` in `.env.example` to emphasize its
importance for proper functioning, especially for local development.

Updated the catch-all handler in
`apps/api/app/api/auth/[...all]/route.ts` to directly use the
`auth.handler` from `better-auth`, simplifying the configuration.

Corrected the file path for the TypeScript route definitions in
`apps/api/next-env.d.ts`.

In the iOS app, updated the API endpoints called for passkey sign-in and
registration in `AppState.swift` to include the `/api` prefix, ensuring
they match the backend routes.

Refactored `SignInView.swift` to provide a cleaner and more intuitive
user experience:
- Introduced a toggle (`usePasskey`) to switch between passkey and
  email/password authentication.
- Redesigned the UI with distinct sections for each authentication
  method.
- Enhanced the email and password form with better styling and
  validation feedback.
- Added a "Continue" button for email/password sign-in and "Continue
  with Passkey" for passkey authentication.
- Modified the `authenticate` and `authenticateWithPasskey` functions to
  correctly invoke the `AppState` methods.

Updated `SignUpView.swift` to use the `authenticate` method for
consistency, which handles both sign-up and sign-in flows.
2026-04-13 19:10:33 +01:00
.deployment i call bagsy on the initial commit 2026-03-27 17:05:28 +00:00
.github/workflows feat: add GitHub Actions ad-hoc iOS build workflow 2026-03-28 08:01:08 +00:00
apps Fix: Improve better-auth integration and passkey flow 2026-04-13 19:10:33 +01:00
docs i call bagsy on the initial commit 2026-03-27 17:05:28 +00:00
packages/types i call bagsy on the initial commit 2026-03-27 17:05:28 +00:00
scripts chore: clean up project structure 2026-04-13 17:16:11 +01:00
.eslintrc.json i call bagsy on the initial commit 2026-03-27 17:05:28 +00:00
.gitignore i call bagsy on the initial commit 2026-03-27 17:05:28 +00:00
.prettierrc.json i call bagsy on the initial commit 2026-03-27 17:05:28 +00:00
AGENTS.md chore: clean up project structure 2026-04-13 17:16:11 +01:00
app.json fix: resolve React Native 0.76 + Expo 55 compatibility for old architecture 2026-03-27 17:24:57 +00:00
bun.lock feat: Add @simplewebauthn/server dependency 2026-04-13 18:03:55 +01:00
eas.json fix: resolve React Native 0.76 + Expo 55 compatibility for old architecture 2026-03-27 17:24:57 +00:00
FILE_STRUCTURE.txt chore: clean up project structure 2026-04-13 17:16:11 +01:00
FINAL_STATUS.txt chore: clean up project structure 2026-04-13 17:16:11 +01:00
package.json i call bagsy on the initial commit 2026-03-27 17:05:28 +00:00
PROJECT_STATUS.md added extra bits and bobs 2026-04-13 17:46:48 +01:00
README.md chore: clean up project structure 2026-04-13 17:16:11 +01:00
sst.config.ts i call bagsy on the initial commit 2026-03-27 17:05:28 +00:00
STATUS.txt chore: clean up project structure 2026-04-13 17:16:11 +01:00
tsconfig.json i call bagsy on the initial commit 2026-03-27 17:05:28 +00:00
turbo.json i call bagsy on the initial commit 2026-03-27 17:05:28 +00:00

Bagsy — Family Shopping List App

A native iOS shopping list app built with Swift/SwiftUI and a TypeScript/Node.js backend.

What is Bagsy?

Bagsy lets families share and sync shopping lists in real time. Key features:

  • Passkey authentication (Face ID / Touch ID) + email/password fallback
  • Household management — invite family members via 6-character join codes
  • Shopping lists organized by store aisle
  • Real-time sync across devices via WebSocket
  • AI product suggestions (OpenRouter)
  • Barcode scanning support
  • Full dark mode

Architecture

/
├── apps/
│   ├── api/               # Next.js 16 backend (API routes only, port 3001)
│   │   ├── app/api/       # Route handlers (auth, households, lists, items, stores, ai)
│   │   ├── db/            # Drizzle ORM schema + PostgreSQL connection
│   │   ├── lib/           # auth.ts, websocket.ts, middleware
│   │   └── server.ts      # Custom HTTP server (WebSocket + local IP display)
│   │
│   └── ios/Bagsy/         # Native Swift/SwiftUI iOS app
│       └── Bagsy/ShopList/
│           ├── App/       # AppState & lifecycle
│           ├── Core/      # API client, Keychain, Cache, WebSocket, Theme
│           ├── Features/  # Auth, Lists, Stores screens
│           └── Models/    # Data models
│
└── packages/
    └── types/             # Shared TypeScript types

Stack

Layer Technology
iOS app Swift 5.9+, SwiftUI, Combine
Backend Node.js 20+, Next.js 16, TypeScript
Database PostgreSQL + Drizzle ORM
Auth Better Auth (passkey, email/password, magic link, organizations)
Real-time WebSocket (ws)
AI Vercel AI SDK + OpenRouter
Monorepo Turborepo + bun workspaces

Running Locally

Prerequisites

  • macOS 12+ with Xcode 14+
  • bun 1.2+
  • PostgreSQL 13+

1. Install dependencies

bun install

2. Configure the backend

cp apps/api/.env.example apps/api/.env.local

Edit apps/api/.env.local:

BETTER_AUTH_SECRET=$(openssl rand -base64 32)
BETTER_AUTH_URL=http://localhost:3001
DATABASE_URL=postgresql://user:password@localhost:5432/bagsy
OPENROUTER_API_KEY=sk-or-...   # optional, for AI suggestions
NODE_ENV=development
PORT=3001

3. Apply database migrations

cd apps/api
bun run db:push

4. Start the backend

cd apps/api
bun run dev
# Prints local network IP for iOS simulator/device

5. Open the iOS app

cd apps/ios/Bagsy
open Bagsy.xcodeproj
# Press Cmd+R in Xcode to build and run

Update the server URL in AppState.swift to match the IP printed by the backend:

let serverURL = URL(string: "http://192.168.x.x:3001")!

Deploying

The backend is a standard Next.js app with a custom Node server. Deploy to any provider that supports Node.js.

Vercel

cd apps/api
npx vercel deploy

Note: Vercel serverless functions don't support WebSocket. Use Railway or Render for full WebSocket support.

Railway / Render

  1. Connect your repository.
  2. Set the root directory to apps/api.
  3. Set build command: bun run build
  4. Set start command: bun run start
  5. Add environment variables (see below).

Required environment variables (production)

BETTER_AUTH_SECRET=<openssl rand -base64 32>
BETTER_AUTH_URL=https://api.yourdomain.com
DATABASE_URL=postgresql://...
OPENROUTER_API_KEY=...   # optional
NODE_ENV=production

iOS release build

cd apps/ios/Bagsy
xcodebuild archive -scheme Bagsy -configuration Release
# Upload via Xcode Organizer or Transporter.app

Auth Setup (Better Auth + Passkeys)

Auth is configured in apps/api/lib/auth.ts using Better Auth.

Plugins enabled:

  • organization — maps to Bagsy "households" (family groups)
  • passkey — WebAuthn / Face ID / Touch ID
  • magicLink — email magic links (logs to console in dev; wire up a mail provider for prod)

Key routes (all under /api/auth/[...all]):

Endpoint Description
POST /api/auth/sign-up/email Register with email + password
POST /api/auth/sign-in/email Sign in with email + password
POST /api/auth/passkey/generate-registration-options Begin passkey registration
POST /api/auth/passkey/verify-registration Complete passkey registration
POST /api/auth/passkey/generate-authentication-options Begin passkey sign-in
POST /api/auth/passkey/verify-authentication Complete passkey sign-in

Requirements:

  • PostgreSQL is required (passkey and organization tables need it)
  • BETTER_AUTH_SECRET must be set and stable (changing it invalidates all sessions)
  • BETTER_AUTH_URL must match the actual origin the app connects to (used as WebAuthn rpID)

iOS client uses @better-auth/expo for cookie/session management compatible with native HTTP clients.

Common Issues

iOS can't connect to API

  • Confirm backend is running: ps aux | grep node
  • Make sure the IP in AppState.swift matches what bun run dev printed
  • Device and Mac must be on the same Wi-Fi network

Passkey endpoints return empty responses

  • Ensure BETTER_AUTH_URL is set correctly in .env.local
  • The passkey plugin reads baseURL to derive the WebAuthn rpID
  • Restart the backend after changing env vars

Database connection errors

  • Confirm DATABASE_URL is set and PostgreSQL is running
  • Re-run bun run db:push after schema changes