0.2 在线版本打通
This commit is contained in:
@@ -4,6 +4,7 @@ import "./globals.css";
|
||||
import { SupabaseProvider } from "@/components/providers/supabase-provider";
|
||||
import { QueryProvider } from "@/components/providers/query-provider";
|
||||
import { createSupabaseServerClient } from "@/lib/supabase/server";
|
||||
import { getMnoteRuntimeConfig } from "@/lib/runtime-config";
|
||||
|
||||
const inter = Inter({
|
||||
subsets: ["latin"],
|
||||
@@ -20,13 +21,30 @@ export default async function RootLayout({
|
||||
}: Readonly<{
|
||||
children: React.ReactNode;
|
||||
}>) {
|
||||
const supabase = await createSupabaseServerClient();
|
||||
const {
|
||||
data: { session },
|
||||
} = await supabase.auth.getSession();
|
||||
const isDesktop = process.env.MNOTE_DESKTOP === "1";
|
||||
|
||||
let session = null;
|
||||
try {
|
||||
session = (await (await createSupabaseServerClient()).auth.getSession()).data.session;
|
||||
} catch {
|
||||
// 说明:不阻塞页面渲染,交由客户端登录页处理(例如网络暂不可达)。
|
||||
session = null;
|
||||
}
|
||||
|
||||
const runtimeConfig = { ...getMnoteRuntimeConfig(), isDesktop };
|
||||
const runtimeConfigJson = JSON.stringify(runtimeConfig).replace(/</g, "\\u003cc");
|
||||
|
||||
return (
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<script
|
||||
// 说明:桌面端需要“运行期可覆盖”的配置(避免 build 时把 NEXT_PUBLIC_* 写死)。
|
||||
// 这里将服务端读取到的配置注入到 window,客户端再优先读取它。
|
||||
dangerouslySetInnerHTML={{
|
||||
__html: `window.__MNOTE_RUNTIME_CONFIG__=${runtimeConfigJson};`,
|
||||
}}
|
||||
/>
|
||||
</head>
|
||||
<body className={`${inter.variable} antialiased`}>
|
||||
<SupabaseProvider session={session}>
|
||||
<QueryProvider>{children}</QueryProvider>
|
||||
|
||||
Reference in New Issue
Block a user