|
3 | 3 | import { Inter } from "next/font/google"; |
4 | 4 | import "./globals.css"; |
5 | 5 | import { SessionProvider, useSession, signIn } from "next-auth/react"; |
6 | | -import { useEffect, useState } from "react"; |
| 6 | +import { useEffect } from "react"; |
7 | 7 |
|
8 | 8 | const inter = Inter({ subsets: ["latin"] }); |
9 | 9 |
|
@@ -35,28 +35,14 @@ export default function RootLayout({ |
35 | 35 |
|
36 | 36 | function AuthGuard({ children }: { children: React.ReactNode }) { |
37 | 37 | const { data: session, status } = useSession(); |
38 | | - const [allowedEmails, setAllowedEmails] = useState<string[]>([]); |
39 | 38 |
|
40 | | - useEffect(() => { |
41 | | - const fetchAllowedEmails = async () => { |
42 | | - const response = await fetch("/api/auth/allowed-emails"); |
43 | | - const emails = await response.json(); |
44 | | - setAllowedEmails(emails); |
45 | | - }; |
46 | | - fetchAllowedEmails(); |
47 | | - }, []); |
48 | | - |
49 | | - if (status === "loading" || allowedEmails.length === 0) { |
50 | | - return <div>読み込み中...</div>; // ローディング状態 |
| 39 | + if (status === "loading") { |
| 40 | + return <div>読み込み中...</div>; |
51 | 41 | } |
52 | 42 |
|
53 | 43 | if (!session?.user) { |
54 | | - return <div>ログインが必要です。</div>; // 未ログインの場合 |
55 | | - } |
56 | | - |
57 | | - if (!allowedEmails.includes(session.user.email || "")) { |
58 | | - return <div>認可されていないアカウントです。</div>; // 許可されていない場合 |
| 44 | + return <div>ログインが必要です。</div>; |
59 | 45 | } |
60 | 46 |
|
61 | | - return <>{children}</>; // 許可された場合のみ子要素を表示 |
| 47 | + return <>{children}</>; |
62 | 48 | } |
0 commit comments