forked from jordanlambrecht/tracker-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlayout.tsx
More file actions
35 lines (29 loc) · 1.01 KB
/
Copy pathlayout.tsx
File metadata and controls
35 lines (29 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// src/app/(auth)/layout.tsx
import { redirect } from "next/navigation"
import type { ReactNode } from "react"
import { AuthShell } from "@/components/layout/AuthShell"
import { getSession } from "@/lib/auth"
import { db } from "@/lib/db"
import { appSettings } from "@/lib/db/schema"
import { ensureSchedulerRunning } from "@/lib/scheduler"
import { QueryProvider } from "./QueryProvider"
export const dynamic = "force-dynamic"
export default async function AuthLayout({ children }: { children: ReactNode }) {
const [[settings], session] = await Promise.all([
db.select({ id: appSettings.id }).from(appSettings).limit(1),
getSession(),
])
if (!settings) redirect("/setup")
if (!session) redirect("/login")
// Auto-restart scheduler if it died (i.e. server restart).
try {
ensureSchedulerRunning(session.encryptionKey)
} catch (err) {
console.error("[auth-layout] Scheduler startup failed:", err)
}
return (
<QueryProvider>
<AuthShell>{children}</AuthShell>
</QueryProvider>
)
}