Skip to content

Fix PWA push notifications and add Icelandic WOD support#136

Merged
Peleke merged 7 commits intostagingfrom
bugfix/pwa-push-notifications
Jan 7, 2026
Merged

Fix PWA push notifications and add Icelandic WOD support#136
Peleke merged 7 commits intostagingfrom
bugfix/pwa-push-notifications

Conversation

@Peleke
Copy link
Owner

@Peleke Peleke commented Dec 23, 2025

Summary

  • Fixes critical bugs preventing push notifications from working
  • Adds Icelandic language support for Word of Day feature
  • Creates test notification endpoint for debugging

Closes #134

Root Causes Fixed

1. Subscription Data Structure Mismatch (CRITICAL)

Subscribe endpoint saved nested JSONB { subscription: { endpoint, keys: { p256dh, auth } } } but CRON jobs expected flat structure { endpoint, p256dh_key, auth_key }.

2. Supabase Client Scope Issue

Helper functions in CRON jobs referenced supabase variable declared in outer GET handler scope.

3. Missing Push Event Handlers

Service worker auto-generated by Workbox lacked push and notificationclick event handlers.

4. Missing Test Endpoint

NotificationSettings UI called non-existent /api/admin/test-push-notification.

Changes Made

File Change
app/api/cron/daily-notifications/route.ts Fixed subscription parsing
app/api/cron/welcome-notifications/route.ts Fixed parsing + Supabase scope
app/api/cron/daily-word-generation/route.ts Fixed parsing + Supabase scope + Icelandic
app/api/admin/test-push-notification/route.ts NEW - Test endpoint
worker/index.js NEW - Custom SW with push handlers
next.config.ts Added customWorkerDir: 'worker'
lib/mastra/tools/wordOfDay.ts Added Icelandic word list
app/api/generate-word-of-day/route.ts Added Icelandic validation
app/api/word-of-day/route.ts Added Icelandic validation
app/api/word-of-day/fresh-sentences/route.ts Added Icelandic validation
lib/mastra/workflows/wordOfDayGeneration.ts Added Icelandic prompts

Test Plan

UAT: Push Notifications

TC1: Android Chrome

  1. Open app in Chrome on Android
  2. Go to Profile → Notification Settings
  3. Click "Enable Notifications"
  4. Accept browser permission prompt
  5. Expected: Status shows "Notifications enabled"
  6. Click "Test Notification"
  7. Expected: Push notification received on device

TC2: iOS Safari PWA

  1. Open app in Safari on iOS 16.4+
  2. Tap Share → "Add to Home Screen"
  3. Open app from Home Screen (required for iOS push)
  4. Go to Profile → Notification Settings
  5. Click "Enable Notifications"
  6. Accept iOS permission prompt
  7. Expected: Status shows "Notifications enabled"
  8. Click "Test Notification"
  9. Expected: Push notification received

TC3: Desktop Browser

  1. Open app in Chrome/Firefox/Safari
  2. Go to Profile → Notification Settings
  3. Enable notifications and test
  4. Expected: Desktop notification appears

UAT: Icelandic WOD

TC4: Generate Icelandic Word

curl -X POST https://staging.example.com/api/generate-word-of-day \
  -H "Content-Type: application/json" \
  -d '{"language": "icelandic", "date": "2024-01-15"}'

Expected: Returns Icelandic word with definitions

TC5: Fetch Icelandic Word

curl "https://staging.example.com/api/word-of-day?language=icelandic"

Expected: Returns word data for Icelandic

Verification Checklist

  • Push notifications work on Android Chrome
  • Push notifications work on iOS Safari (PWA installed)
  • Push notifications work on desktop browsers
  • Test notification button works
  • Icelandic WOD generation works
  • Existing Spanish/Latin WOD still works
  • CRON job sends notifications correctly

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 4.5 noreply@anthropic.com

Peleke Sengstacke and others added 7 commits December 23, 2025 07:07
Fixes #134

## Critical Bug Fixes

### 1. Subscription Data Structure Mismatch
- Subscribe endpoint saves nested JSONB: `{ subscription: { endpoint, keys } }`
- CRON jobs expected flat structure: `{ endpoint, p256dh_key, auth_key }`
- Updated all CRON jobs to parse nested structure correctly

### 2. Supabase Client Scope Issues
- Helper functions in CRON routes referenced `supabase` out of scope
- Fixed by passing supabase client as parameter to helper functions

### 3. Missing Test Notification Endpoint
- Created `/api/admin/test-push-notification` endpoint
- Allows users to test push notifications from settings

### 4. Service Worker Missing Push Handlers
- Added custom worker directory with push event handlers
- Handles push, notificationclick, and pushsubscriptionchange events
- Updated next.config.ts to use customWorkerDir

## New Features

### Icelandic Word of Day Support
- Added Icelandic word list (27 words)
- Added Icelandic content dictionary with real examples
- Updated all WOD API routes to accept 'icelandic' language
- Added Icelandic notification strings in CRON job

## Files Changed
- app/api/cron/daily-notifications/route.ts
- app/api/cron/welcome-notifications/route.ts
- app/api/cron/daily-word-generation/route.ts
- app/api/admin/test-push-notification/route.ts (NEW)
- app/api/generate-word-of-day/route.ts
- app/api/word-of-day/route.ts
- app/api/word-of-day/fresh-sentences/route.ts
- lib/mastra/tools/wordOfDay.ts
- lib/mastra/workflows/wordOfDayGeneration.ts
- next.config.ts
- worker/index.js (NEW)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Code expected ELEVEN_LABS_API_KEY but GCP secrets use ELEVENLABS_API_KEY.
Updated to match deployed configuration.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Add supabase client initialization to POST handler (was undefined)
- Add comprehensive dark mode styling to word-of-day page

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Add 🇮🇸 Íslenska button to language toggle
- Add Icelandic header: "Orðið dagsins"
- Add Icelandic section headers: Skilgreiningar, Dæmi
- Support icelandic sentence display in examples

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Update check constraint to allow 'icelandic' language for Word of Day.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@Peleke
Copy link
Owner Author

Peleke commented Jan 7, 2026

✅ UAT Complete

Tests Performed

PWA Installation

  • Installed PWA on iOS Safari ✅
  • App icon and splash screen display correctly ✅
  • Standalone mode works ✅

Push Notifications (Partial)

  • Notification permission prompt works ✅
  • Service worker registration successful ✅
  • Note: Full push notification testing requires mobile device + production VAPID keys

Word of Day - Icelandic Support

  • Toggled language to Icelandic on WOD page ✅
  • Icelandic words display with correct formatting ✅
  • Audio pronunciation works via ElevenLabs ✅
  • Dark mode styling applied correctly ✅

Supabase Scope Fix

  • WOD fetches work without authentication errors ✅
  • User preferences persist correctly ✅

Fixes Cherry-Picked from UAT

  • ffc5e99 Fix WOD supabase scope bug and add dark mode support
  • c3263c3 feat(wod): Add Icelandic language toggle to Word of Day page
  • e160ca0 migration: Add Icelandic to daily_words language constraint

Migrations Required

  1. 20260107_add_icelandic_to_daily_words.sql

Notes

  • Supabase email templates for password reset need dashboard config check
  • Full push notification testing recommended on mobile before production

Ready to merge 🚀

@Peleke Peleke merged commit 1bf48ae into staging Jan 7, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant