managarten/memoro/apps/web/docs/archive/SPA_CONVERSION_COMPLETE.md
Till-JS e7f5f942f3 chore: initial commit - consolidate 4 projects into monorepo
Projects included:
- maerchenzauber (NestJS backend + Expo mobile + SvelteKit web + Astro landing)
- manacore (Expo mobile + SvelteKit web + Astro landing)
- manadeck (NestJS backend + Expo mobile + SvelteKit web)
- memoro (Expo mobile + SvelteKit web + Astro landing)

This commit preserves the current state before monorepo restructuring.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-22 23:38:24 +01:00

6.1 KiB

Pure SPA Conversion Complete!

🎉 memoro-web is now a Pure Client-Side SPA (Like memoro_app)

Date: October 27, 2025 Status: COMPLETE


📊 What Changed

Configuration

  • Installed @sveltejs/adapter-static
  • Removed @sveltejs/adapter-auto (SSR adapter)
  • Removed @supabase/ssr (no longer needed)
  • Updated svelte.config.js to SPA mode with fallback

Server-Side Files Removed (8 files)

  • src/hooks.server.ts - Server hooks
  • src/routes/+layout.server.ts - Root layout server load
  • src/routes/(protected)/+layout.server.ts - Protected route auth guard
  • src/routes/(protected)/memos/+page.server.ts - SSR memo loading
  • src/routes/(protected)/memos/[id]/+page.server.ts - SSR single memo
  • src/routes/(protected)/tags/+page.server.ts - SSR tags + form actions
  • src/routes/(public)/register/+page.server.ts - Server-side registration
  • src/routes/auth/callback/+server.ts - OAuth callback handler

Pages Converted to Client-Side

Authentication Pages

  • Login - Client-side form, calls middleware API directly
  • Register - Client-side form with validation, calls middleware API directly
  • OAuth Callback - Client-side handling of OAuth redirects

Protected Pages

  • Protected Layout - Client-side auth guard with redirect
  • Memos List - Loads data via memoService on mount
  • Single Memo - Loads memo by ID with access control
  • Tags - Full CRUD operations client-side

🏗️ New Architecture

Browser (memoro-web SPA)
    ↓
    ├─→ Supabase (direct client calls with JWT)
    │   └─→ Memos, Tags, Spaces tables
    │
    └─→ Middleware API (direct fetch calls)
         ├─→ POST /auth/signin
         ├─→ POST /auth/signup
         ├─→ POST /auth/refresh
         ├─→ POST /auth/google-signin
         └─→ POST /auth/logout

No server-side code. Pure client-side. Exactly like memoro_app.


Benefits Achieved

  1. Consistency - Now matches memoro_app architecture exactly
  2. Simplicity - No server-side complexity
  3. Deployment - Can host on any static file server (Netlify, Vercel, S3)
  4. Performance - No server round-trips for routing
  5. Debugging - All API calls visible in browser Network tab
  6. Development - Faster dev experience, no server restarts needed

🚀 Next Steps

1. Restart Dev Server

Your dev server needs to be restarted to pick up the new configuration:

# Stop current dev server (Ctrl+C)

# Start fresh
cd /Users/wuesteon/memoro_new/mana-2025/memoro-web
npm run dev

2. Test the Application

Open http://localhost:5173 and test:

  • Login - Should call https://memoro-service-.../auth/signin
  • Register - Should call https://memoro-service-.../auth/signup
  • Logout - Should clear tokens and redirect
  • Protected Routes - Should redirect to login if not authenticated
  • Memos Page - Should load memos from Supabase
  • Tags Page - Should allow CRUD operations

3. Check Browser Network Tab

All API calls are now visible! You should see:

  • Direct calls to https://memoro-service-111768794939.europe-west3.run.app
  • Direct calls to Supabase
  • No calls to localhost:5173 for data (only for static assets)

4. Build for Production

When ready to deploy:

npm run build

This creates a build/ directory with static files that can be hosted anywhere.


🔍 Key Implementation Details

Client-Side Auth Guard

Protected routes now use onMount to check authentication:

<script>
  onMount(() => {
    if (!$isAuthenticated) {
      goto(`/login?redirectTo=${$page.url.pathname}`);
    } else {
      loading = false;
    }
  });
</script>

Client-Side Data Loading

All pages load data in onMount:

onMount(async () => {
  const data = await memoService.getMemos($user.id);
  setMemos(data);
});

Direct API Calls

All API calls go through services that use fetch():

const response = await fetch(`${MIDDLEWARE_URL}/auth/signin?appId=${APP_ID}`, {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({ email, password, deviceInfo })
});

📝 Important Notes

  • ⚠️ Tokens stored in localStorage (not httpOnly cookies)
  • ⚠️ All API calls visible in browser Network tab (as intended)
  • ⚠️ No SSR - SEO limited (but not important for authenticated app)
  • ⚠️ Client-side routing - All routes handled by SPA router
  • Same as mobile app - Identical architecture to memoro_app

🎯 Success Criteria

Your app is now a pure SPA when:

  • No .server.ts files exist in src/
  • All API calls visible in browser Network tab
  • Login redirects work client-side
  • Protected routes check auth on mount
  • Data loads asynchronously with loading states
  • Build creates static files only

🐛 Troubleshooting

If you see "404 Not Found" on refresh:

  • Check that fallback: 'index.html' is in svelte.config.js
  • Ensure your hosting platform supports SPA routing

If auth doesn't work:

  • Check browser console for errors
  • Verify middleware URL in .env
  • Check localStorage for tokens

If protected routes don't redirect:

  • Check that auth store is initialized
  • Verify onMount hook is running
  • Check browser console for auth errors

📚 Files to Reference

  • Config: svelte.config.js - SPA adapter configuration
  • Auth Store: src/lib/stores/auth.ts - Client-side auth state
  • Auth Service: src/lib/services/authService.ts - Middleware API calls
  • Protected Layout: src/routes/(protected)/+layout.svelte - Auth guard
  • Environment: .env - Middleware URLs

🎊 Conclusion

memoro-web is now a pure client-side SPA, just like memoro_app!

All API calls happen directly from the browser, making debugging easier and architecture consistent across platforms.

Ready to test! 🚀

Start your dev server and try logging in - you'll see the API call to the middleware in your browser's Network tab!