完成页面的基础配置
This commit is contained in:
@@ -3,13 +3,18 @@ import { cookies } from "next/headers";
|
||||
import React, { Suspense } from "react";
|
||||
import { RefineContext } from "./_refine_context";
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: "Refine",
|
||||
description: "Generated by create refine app",
|
||||
icons: {
|
||||
icon: "/favicon.ico",
|
||||
},
|
||||
};
|
||||
import authOptions from "@app/api/auth/[...nextauth]/options";
|
||||
import { Header } from "@components/header";
|
||||
import { Title } from "@components/title";
|
||||
import { ThemedLayout } from "@refinedev/mui";
|
||||
import { getServerSession } from "next-auth/next";
|
||||
import { redirect } from "next/navigation";
|
||||
|
||||
import "./globals.css";
|
||||
|
||||
import { META_DATA } from "@config/config";
|
||||
|
||||
export const metadata: Metadata = META_DATA;
|
||||
|
||||
export default async function RootLayout({
|
||||
children,
|
||||
@@ -20,13 +25,39 @@ export default async function RootLayout({
|
||||
const theme = cookieStore.get("theme");
|
||||
const defaultMode = theme?.value === "dark" ? "dark" : "light";
|
||||
|
||||
const data = await getData();
|
||||
|
||||
if (!data.session?.user) {
|
||||
return redirect("/login");
|
||||
}
|
||||
|
||||
return (
|
||||
<html lang="en">
|
||||
<body>
|
||||
<Suspense>
|
||||
<RefineContext defaultMode={defaultMode}>{children}</RefineContext>
|
||||
<RefineContext defaultMode={defaultMode}>
|
||||
<ThemedLayout
|
||||
Header={Header}
|
||||
Title={Title}
|
||||
childrenBoxProps={{
|
||||
sx: { height: "100vh", p: 0 },
|
||||
}}
|
||||
containerBoxProps={{
|
||||
sx: { height: "100%" }, // 修改根容器:占满视口
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
</ThemedLayout>
|
||||
</RefineContext>
|
||||
</Suspense>
|
||||
</body>
|
||||
</html>
|
||||
);
|
||||
}
|
||||
|
||||
async function getData() {
|
||||
const session = await getServerSession(authOptions);
|
||||
return {
|
||||
session,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user