Scrum4Me/lib/auth-guard.ts
Madhura68 7b32fc60e6 feat(ST-1134): (mobile) route group + auth-guard helper + manifest (T-321)
- 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>
2026-05-04 09:55:18 +02:00

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
}