Prettier format pending files

This commit is contained in:
Builder.io 2025-11-17 04:20:27 +00:00
parent e732100390
commit aa434933ab
2 changed files with 15 additions and 3 deletions

View file

@ -312,7 +312,9 @@ async function syncUserToLocalDatabase(
// ONE-WAY SYNC: Upsert Foundation data to local cache // ONE-WAY SYNC: Upsert Foundation data to local cache
// Note: This is the ONLY place where user_profiles should be written to // Note: This is the ONLY place where user_profiles should be written to
const now = new Date().toISOString(); const now = new Date().toISOString();
const cacheValidUntil = new Date(Date.now() + 24 * 60 * 60 * 1000).toISOString(); // 24 hour cache TTL const cacheValidUntil = new Date(
Date.now() + 24 * 60 * 60 * 1000,
).toISOString(); // 24 hour cache TTL
const { error } = await supabase.from("user_profiles").upsert({ const { error } = await supabase.from("user_profiles").upsert({
id: foundationUser.id, id: foundationUser.id,

View file

@ -16,6 +16,7 @@ Each Platform = Read-only cache of Foundation passport data
## Architecture ## Architecture
### 1. Foundation (aethex.foundation) ### 1. Foundation (aethex.foundation)
- **Owner of passport data** - **Owner of passport data**
- Issues and maintains all user identities - Issues and maintains all user identities
- Provides OAuth endpoints for authentication - Provides OAuth endpoints for authentication
@ -23,6 +24,7 @@ Each Platform = Read-only cache of Foundation passport data
- Single authority for all identity mutations (updates, deletions) - Single authority for all identity mutations (updates, deletions)
### 2. Client Platforms (aethex.dev, etc.) ### 2. Client Platforms (aethex.dev, etc.)
- **Consumers of Foundation identities** - **Consumers of Foundation identities**
- Cache Foundation passport data locally for performance - Cache Foundation passport data locally for performance
- Use cached data for reads (lookups, profile queries) - Use cached data for reads (lookups, profile queries)
@ -112,11 +114,11 @@ CREATE TABLE user_profiles (
full_name TEXT, -- From Foundation full_name TEXT, -- From Foundation
avatar_url TEXT, -- From Foundation avatar_url TEXT, -- From Foundation
profile_completed BOOLEAN DEFAULT false,-- From Foundation profile_completed BOOLEAN DEFAULT false,-- From Foundation
-- Sync tracking -- Sync tracking
foundation_synced_at TIMESTAMP, -- When last synced from Foundation foundation_synced_at TIMESTAMP, -- When last synced from Foundation
cache_valid_until TIMESTAMP, -- When cache expires cache_valid_until TIMESTAMP, -- When cache expires
-- Local metadata (not from Foundation) -- Local metadata (not from Foundation)
last_login_at TIMESTAMP, -- aethex.dev tracking only last_login_at TIMESTAMP, -- aethex.dev tracking only
created_at TIMESTAMP, created_at TIMESTAMP,
@ -130,6 +132,7 @@ CREATE TABLE user_profiles (
## Sync Mechanism ## Sync Mechanism
### Initial Sync (On Login) ### Initial Sync (On Login)
1. User authenticates with Foundation 1. User authenticates with Foundation
2. aethex.dev receives `access_token` and basic user info 2. aethex.dev receives `access_token` and basic user info
3. aethex.dev calls Foundation's `/api/oauth/userinfo` endpoint 3. aethex.dev calls Foundation's `/api/oauth/userinfo` endpoint
@ -137,6 +140,7 @@ CREATE TABLE user_profiles (
5. `foundation_synced_at` timestamp is updated 5. `foundation_synced_at` timestamp is updated
### Periodic Sync (Background) ### Periodic Sync (Background)
``` ```
Every 24 hours (or on explicit request): Every 24 hours (or on explicit request):
1. Fetch current user data from Foundation API 1. Fetch current user data from Foundation API
@ -147,6 +151,7 @@ Every 24 hours (or on explicit request):
``` ```
### Cache Expiration ### Cache Expiration
``` ```
If (now > cache_valid_until): If (now > cache_valid_until):
1. Treat cache as stale 1. Treat cache as stale
@ -159,16 +164,19 @@ If (now > cache_valid_until):
### What if Foundation is unavailable? ### What if Foundation is unavailable?
**During Login:** **During Login:**
- <20><> Cannot proceed - user must authenticate through Foundation - <20><> Cannot proceed - user must authenticate through Foundation
- Return error: "Identity service unavailable" - Return error: "Identity service unavailable"
**For existing users (cache valid):** **For existing users (cache valid):**
- ✅ Can use cached data temporarily - ✅ Can use cached data temporarily
- Continue serving from cache - Continue serving from cache
- Log warning about Foundation unavailability - Log warning about Foundation unavailability
- Retry sync in background - Retry sync in background
**For profile updates:** **For profile updates:**
- ❌ Cannot proceed - updates must go through Foundation - ❌ Cannot proceed - updates must go through Foundation
- Queue update locally, retry when Foundation is available - Queue update locally, retry when Foundation is available
- Or fail gracefully: "Identity service unavailable, please try again" - Or fail gracefully: "Identity service unavailable, please try again"
@ -176,6 +184,7 @@ If (now > cache_valid_until):
## Validation Rules ## Validation Rules
### On Every Auth Request ### On Every Auth Request
```javascript ```javascript
if (!user.foundation_synced_at) { if (!user.foundation_synced_at) {
throw new Error("User not synced from Foundation"); throw new Error("User not synced from Foundation");
@ -190,6 +199,7 @@ if (now > user.cache_valid_until) {
``` ```
### On Every Profile Update Request ### On Every Profile Update Request
```javascript ```javascript
// Forward to Foundation API, never write locally // Forward to Foundation API, never write locally
const updated = await foundation.api.updateProfile(userId, changes); const updated = await foundation.api.updateProfile(userId, changes);