Add user authentication and role management
This commit is contained in:
25
app/page.tsx
25
app/page.tsx
@@ -1,24 +1,13 @@
|
||||
import { chatGPTSignOutPath, requireChatGPTUser } from "./chatgpt-auth";
|
||||
import { headers } from "next/headers";
|
||||
import { redirect } from "next/navigation";
|
||||
import AdminApp from "./admin-app";
|
||||
import { isAdminEmail } from "../lib/admin-auth";
|
||||
import { getUserFromCookieHeader } from "../lib/user-auth";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
export default async function Page() {
|
||||
const user = await requireChatGPTUser("/");
|
||||
|
||||
if (!isAdminEmail(user.email)) {
|
||||
return (
|
||||
<main className="admin-access-denied">
|
||||
<section>
|
||||
<p>KOC LOOP</p>
|
||||
<h1>当前账号没有后台权限</h1>
|
||||
<span>请切换为管理员账号后再试。</span>
|
||||
<a href={chatGPTSignOutPath("/")}>切换账号</a>
|
||||
</section>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
|
||||
return <AdminApp />;
|
||||
const requestHeaders = await headers();
|
||||
const user = await getUserFromCookieHeader(requestHeaders.get("cookie"));
|
||||
if (!user) redirect("/login");
|
||||
return <AdminApp currentUser={user} />;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user