Spaces:
Runtime error
Runtime error
Đào Minh Tú commited on
Commit ·
3c5ffff
1
Parent(s): 747e7c5
fix(auth): gate SessionProvider + CloudSyncButton behind NEXT_PUBLIC_ENABLE_CLOUD_SYNC=1
Browse filesHF Space crashed because NextAuth requires NEXTAUTH_SECRET in production
and SessionProvider auto-fetches /api/auth/session on mount. With
cloud-sync env vars unset, that 500s and brings down the space.
Now: cloud-sync UI + provider only render when explicitly enabled. Set
NEXT_PUBLIC_ENABLE_CLOUD_SYNC=1 (plus the 6 backend env vars) to re-enable.
components/auth-provider.tsx
CHANGED
|
@@ -2,6 +2,11 @@
|
|
| 2 |
import { SessionProvider } from "next-auth/react"
|
| 3 |
import { ReactNode } from "react"
|
| 4 |
|
|
|
|
|
|
|
| 5 |
export function AuthProvider({ children }: { children: ReactNode }) {
|
|
|
|
|
|
|
|
|
|
| 6 |
return <SessionProvider>{children}</SessionProvider>
|
| 7 |
}
|
|
|
|
| 2 |
import { SessionProvider } from "next-auth/react"
|
| 3 |
import { ReactNode } from "react"
|
| 4 |
|
| 5 |
+
const ENABLED = process.env.NEXT_PUBLIC_ENABLE_CLOUD_SYNC === "1"
|
| 6 |
+
|
| 7 |
export function AuthProvider({ children }: { children: ReactNode }) {
|
| 8 |
+
// Tắt SessionProvider nếu cloud-sync chưa được cấu hình.
|
| 9 |
+
// Tránh /api/auth/session bị gọi → 500 vì thiếu NEXTAUTH_SECRET.
|
| 10 |
+
if (!ENABLED) return <>{children}</>
|
| 11 |
return <SessionProvider>{children}</SessionProvider>
|
| 12 |
}
|
components/cloud-sync-button.tsx
CHANGED
|
@@ -23,6 +23,13 @@ function formatRelative(ts: number | null): string {
|
|
| 23 |
}
|
| 24 |
|
| 25 |
export function CloudSyncButton() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
const { data: session, status: authStatus } = useSession()
|
| 27 |
const { status, lastSyncAt, error, pullAll, pushAll } = useCloudSync()
|
| 28 |
const [open, setOpen] = useState(false)
|
|
|
|
| 23 |
}
|
| 24 |
|
| 25 |
export function CloudSyncButton() {
|
| 26 |
+
// Tắt hoàn toàn nếu cloud-sync chưa được cấu hình (env NEXT_PUBLIC_ENABLE_CLOUD_SYNC).
|
| 27 |
+
// useSession sẽ throw nếu không có SessionProvider phía trên, nên gate ngay tại đây.
|
| 28 |
+
if (process.env.NEXT_PUBLIC_ENABLE_CLOUD_SYNC !== "1") return null
|
| 29 |
+
return <CloudSyncButtonInner />
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
function CloudSyncButtonInner() {
|
| 33 |
const { data: session, status: authStatus } = useSession()
|
| 34 |
const { status, lastSyncAt, error, pullAll, pushAll } = useCloudSync()
|
| 35 |
const [open, setOpen] = useState(false)
|