From caabf0ac7a1eebfb18b3114e64e0a2785f4fdc65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luc=C3=A0s?= Date: Tue, 28 Mar 2023 15:10:57 +0200 Subject: [PATCH] Add middleware Took 1 hour 8 minutes --- prisma/schema.prisma | 2 +- src/middleware.ts | 9 +++++++++ src/pages/api/auth/[...nextauth].ts | 7 +++++++ 3 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 src/middleware.ts diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 8b21b96..e647059 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -90,7 +90,7 @@ model Chat { model Message { id String @id @default(auto()) @map("_id") @db.ObjectId - message String + text String createdAt DateTime @default(now()) updatedAt DateTime @updatedAt diff --git a/src/middleware.ts b/src/middleware.ts new file mode 100644 index 0000000..7974308 --- /dev/null +++ b/src/middleware.ts @@ -0,0 +1,9 @@ +export { default } from "next-auth/middleware" + +export const config = { + matcher: [ + "/dashboard", + "/profile", + '/chat/:path*' + ] +} \ No newline at end of file diff --git a/src/pages/api/auth/[...nextauth].ts b/src/pages/api/auth/[...nextauth].ts index 1e6524e..104fa83 100644 --- a/src/pages/api/auth/[...nextauth].ts +++ b/src/pages/api/auth/[...nextauth].ts @@ -41,6 +41,13 @@ export default async function auth(req: NextApiRequest, res: NextApiResponse) { return await NextAuth(req, res, { providers, session: {strategy: 'jwt'}, + pages: { + signIn: '/login', + signOut: '/auth/signout', + error: '/auth/error', + verifyRequest: '/auth/verify-request', + newUser: '/auth/new-user' // New users will be directed here on first sign in (leave the property out if not of interest) + }, secret: process.env.NEXTAUTH_SECRET, callbacks: { async session({session, token}: { session: any; token: any }) {