From c2a5bc70164e3713382d3b4537d69a476ba428b9 Mon Sep 17 00:00:00 2001 From: Iceship Date: Fri, 20 Sep 2024 11:15:52 +0900 Subject: [PATCH] refactor: Fix formatting in middleware.ts, route.ts, loading.tsx, and use-system-theme.ts feat: Add next-auth middleware and configure profile route setup env add nextui Delete middleware.ts Add next-auth type declaration --- src/app/guestbook/page.tsx | 12 ++++++++++++ src/app/profile/page.tsx | 1 - src/config/auth.ts | 6 ++++++ src/db/index.ts | 4 +++- src/middleware.ts | 3 --- src/types/next-auth.d.ts | 9 +++++++++ 6 files changed, 30 insertions(+), 5 deletions(-) create mode 100644 src/app/guestbook/page.tsx delete mode 100644 src/middleware.ts create mode 100644 src/types/next-auth.d.ts diff --git a/src/app/guestbook/page.tsx b/src/app/guestbook/page.tsx new file mode 100644 index 0000000..4919cc9 --- /dev/null +++ b/src/app/guestbook/page.tsx @@ -0,0 +1,12 @@ +import { Card, CardBody } from "@nextui-org/react"; + +export default function Guestbook() { + return ( + + +

Guestbook

+

Leave a message for the owner of this guestbook.

+
+
+ ); +} diff --git a/src/app/profile/page.tsx b/src/app/profile/page.tsx index a37ba78..adfe6ec 100644 --- a/src/app/profile/page.tsx +++ b/src/app/profile/page.tsx @@ -7,7 +7,6 @@ import requireAuth from "@/utils/require-auth"; export default async function Profile() { await requireAuth(); const session = (await getServerSession(options))!; - return ( diff --git a/src/config/auth.ts b/src/config/auth.ts index 2534dad..4327542 100644 --- a/src/config/auth.ts +++ b/src/config/auth.ts @@ -12,6 +12,12 @@ const options: NextAuthOptions = { // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-expect-error adapter: DrizzleAdapter(db), + callbacks: { + session({ session, user }) { + session.user.id = user.id; + return session; + }, + }, providers: [ GoogleProvider({ clientId: env.GOOGLE_CLIENT_ID, diff --git a/src/db/index.ts b/src/db/index.ts index 2038896..fa1126b 100644 --- a/src/db/index.ts +++ b/src/db/index.ts @@ -3,9 +3,11 @@ import postgres from "postgres"; import { env } from "@/env/server"; +import * as schema from "./schema/index"; + export const client = postgres(env.DATABASE_URL, { max: env.DB_MIGRATING ? 1 : undefined, }); -const db = drizzle(client); +const db = drizzle(client, { schema }); export default db; diff --git a/src/middleware.ts b/src/middleware.ts deleted file mode 100644 index 3450526..0000000 --- a/src/middleware.ts +++ /dev/null @@ -1,3 +0,0 @@ -export { default } from "next-auth/middleware"; - -export const config = { matcher: ["/profile"] }; diff --git a/src/types/next-auth.d.ts b/src/types/next-auth.d.ts new file mode 100644 index 0000000..41abda7 --- /dev/null +++ b/src/types/next-auth.d.ts @@ -0,0 +1,9 @@ +import { DefaultSession } from "next-auth"; + +declare module "next-auth" { + interface Session { + user: { + id: string; + } & DefaultSession["user"]; + } +}