- lib/auth-guard.ts (nieuw): requireSession() — gedeelde auth+paired-expiry guard, hergebruikt door (app)/layout.tsx - (app)/layout.tsx: refactor naar requireSession() (gedraagt zich identiek) - (mobile)/layout.tsx (nieuw): minimal layout met LandscapeGuard + MobileTabBar; geen NavBar/StatusBar/MinWidthBanner/bridges - /m/pair filesystem-move van (app)/ naar (mobile)/ — URL onveranderd - public/manifest.json: orientation landscape - Tests: requireSession-helper (3 paden) Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
24 lines
623 B
TypeScript
24 lines
623 B
TypeScript
import { redirect } from 'next/navigation'
|
|
import { getSession } from '@/lib/auth'
|
|
import { isPairedSessionExpired } from '@/lib/auth/pairing'
|
|
|
|
/**
|
|
* Layout-side auth guard. Returns the session when valid; otherwise redirects
|
|
* to /login (and destroys an expired paired-session first).
|
|
*
|
|
* Used by both `app/(app)/layout.tsx` (desktop) and `app/(mobile)/layout.tsx`.
|
|
*/
|
|
export async function requireSession() {
|
|
const session = await getSession()
|
|
|
|
if (!session.userId) {
|
|
redirect('/login')
|
|
}
|
|
|
|
if (isPairedSessionExpired(session)) {
|
|
await session.destroy()
|
|
redirect('/login')
|
|
}
|
|
|
|
return session
|
|
}
|