更新依赖项;调整新的目录结构
This commit is contained in:
57
src/app/(main)/layout.tsx
Normal file
57
src/app/(main)/layout.tsx
Normal file
@@ -0,0 +1,57 @@
|
||||
import type { Metadata } from "next";
|
||||
import { cookies } from "next/headers";
|
||||
import React from "react";
|
||||
import { RefineContext } from "../_refine_context";
|
||||
|
||||
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 MainLayout({
|
||||
children,
|
||||
}: Readonly<{
|
||||
children: React.ReactNode;
|
||||
}>) {
|
||||
const cookieStore = await cookies();
|
||||
const theme = cookieStore.get("theme");
|
||||
const defaultMode = theme?.value === "dark" ? "dark" : "light";
|
||||
|
||||
const data = await getData();
|
||||
|
||||
if (!data.session?.user) {
|
||||
return redirect("/login");
|
||||
}
|
||||
|
||||
return (
|
||||
<RefineContext defaultMode={defaultMode}>
|
||||
<ThemedLayout
|
||||
Header={Header}
|
||||
Title={Title}
|
||||
childrenBoxProps={{
|
||||
sx: { height: "100vh", p: 0 },
|
||||
}}
|
||||
containerBoxProps={{
|
||||
sx: { height: "100%" },
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
</ThemedLayout>
|
||||
</RefineContext>
|
||||
);
|
||||
}
|
||||
|
||||
async function getData() {
|
||||
const session = await getServerSession(authOptions);
|
||||
return {
|
||||
session,
|
||||
};
|
||||
}
|
||||
@@ -1,24 +1,24 @@
|
||||
import KeycloakProvider from "next-auth/providers/keycloak";
|
||||
import Avatar from "@assets/avatar/avatar-small.jpeg";
|
||||
|
||||
const authOptions = {
|
||||
// Configure one or more authentication providers
|
||||
providers: [
|
||||
// !!! Should be stored in .env file.
|
||||
KeycloakProvider({
|
||||
clientId: `tjwater`,
|
||||
clientSecret: `Darcm3gw0ZEJhIxt4DQUvacXpVlE7MBt`,
|
||||
issuer: `http://localhost:8088/realms/tjwater`,
|
||||
clientId: process.env.KEYCLOAK_CLIENT_ID!,
|
||||
clientSecret: process.env.KEYCLOAK_CLIENT_SECRET!,
|
||||
issuer: process.env.KEYCLOAK_ISSUER!,
|
||||
profile(profile) {
|
||||
return {
|
||||
id: profile.sub,
|
||||
name: profile.name ?? profile.preferred_username,
|
||||
email: profile.email,
|
||||
image: `https://faces-img.xcdn.link/thumb-lorem-face-6312_thumb.jpg`,
|
||||
image: Avatar.src,
|
||||
};
|
||||
},
|
||||
}),
|
||||
],
|
||||
secret: `Darcm3gw0ZEJhIxt4DQUvacXpVlE7MBt`,
|
||||
secret: process.env.NEXTAUTH_SECRET,
|
||||
};
|
||||
|
||||
export default authOptions;
|
||||
|
||||
@@ -2,16 +2,6 @@ import type { Metadata } from "next";
|
||||
import { cookies } from "next/headers";
|
||||
import React, { Suspense } from "react";
|
||||
import { RefineContext } from "./_refine_context";
|
||||
|
||||
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;
|
||||
@@ -25,39 +15,13 @@ 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}>
|
||||
<ThemedLayout
|
||||
Header={Header}
|
||||
Title={Title}
|
||||
childrenBoxProps={{
|
||||
sx: { height: "100vh", p: 0 },
|
||||
}}
|
||||
containerBoxProps={{
|
||||
sx: { height: "100%" }, // 修改根容器:占满视口
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
</ThemedLayout>
|
||||
</RefineContext>
|
||||
<RefineContext defaultMode={defaultMode}>{children}</RefineContext>
|
||||
</Suspense>
|
||||
</body>
|
||||
</html>
|
||||
);
|
||||
}
|
||||
|
||||
async function getData() {
|
||||
const session = await getServerSession(authOptions);
|
||||
return {
|
||||
session,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user