From 3405f9f515b0cd1c41a61cddb0034e2fe91d26b7 Mon Sep 17 00:00:00 2001 From: devsargam Date: Sun, 31 Mar 2024 21:24:14 +0530 Subject: [PATCH 1/6] fix(dev): improve local development experience --- src/lib/auth.ts | 10 ++++++++++ src/middleware.ts | 2 ++ 2 files changed, 12 insertions(+) diff --git a/src/lib/auth.ts b/src/lib/auth.ts index 11c1c7845..e84ffd331 100644 --- a/src/lib/auth.ts +++ b/src/lib/auth.ts @@ -91,6 +91,16 @@ export const authOptions = { }, async authorize(credentials: any) { try { + if (process.env.LOCAL_CMS_PROVIDER) { + return { + id: '1', + name: 'test', + email: 'test@gmail.com', + token: await generateJWT({ + id: 1, + }), + }; + } const hashedPassword = await bcrypt.hash(credentials.password, 10); const userDb = await prisma.user.findFirst({ diff --git a/src/middleware.ts b/src/middleware.ts index 605cbcea6..8f8d4d953 100644 --- a/src/middleware.ts +++ b/src/middleware.ts @@ -6,6 +6,8 @@ export const config = { }; export default withAuth(async (req) => { + if (process.env.LOCAL_CMS_PROVIDER) return; + const token = req.nextauth.token; if (!token) { return NextResponse.redirect(new URL('/invalidsession', req.url)); From 00b842a1a0d3b3eaf662ff2296c650f8996f225e Mon Sep 17 00:00:00 2001 From: devsargam Date: Sun, 31 Mar 2024 21:36:06 +0530 Subject: [PATCH 2/6] fix(prisma): improve the seed command --- prisma/seed.ts | 46 +++++++++++++++++++++++++++++++--------------- 1 file changed, 31 insertions(+), 15 deletions(-) diff --git a/prisma/seed.ts b/prisma/seed.ts index b26c6078f..c9d55503a 100644 --- a/prisma/seed.ts +++ b/prisma/seed.ts @@ -1,23 +1,39 @@ import db from '../src/db/index'; async function main() { - await db.user.createMany({ - data: [ - { - id: '2', - email: 'testuser', - name: 'Test User 1', - disableDrm: false, - }, - { - id: '1', - email: 'testuser2', - name: 'Test User 2', - disableDrm: false, - }, - ], + await db.user.upsert({ + where: { + id: '2', + email: 'testuser', + }, + create: { + id: '2', + email: 'testuser', + name: 'Test User 1', + disableDrm: false, + }, + update: {}, + }); + + await db.user.upsert({ + where: { + id: '1', + email: 'testuser2', + }, + create: { + id: '1', + email: 'testuser2', + name: 'Test User 2', + disableDrm: false, + }, + update: {}, }); + if (await db.course.findMany()) { + console.error('DB is already seeded!'); + process.exit(0); + } + await db.course.createMany({ data: [ { From 9b9786459e722023f9d1b8d3fbbfe40751dac12f Mon Sep 17 00:00:00 2001 From: devsargam Date: Sun, 31 Mar 2024 21:45:30 +0530 Subject: [PATCH 3/6] fix types --- src/lib/auth.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/auth.ts b/src/lib/auth.ts index e84ffd331..12d152129 100644 --- a/src/lib/auth.ts +++ b/src/lib/auth.ts @@ -97,7 +97,7 @@ export const authOptions = { name: 'test', email: 'test@gmail.com', token: await generateJWT({ - id: 1, + id: '1', }), }; } From 0cc2fa5150c01a736fc64406c756bcac056e2398 Mon Sep 17 00:00:00 2001 From: devsargam Date: Sun, 31 Mar 2024 21:58:35 +0530 Subject: [PATCH 4/6] small fix --- prisma/seed.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/prisma/seed.ts b/prisma/seed.ts index c9d55503a..ae2b32602 100644 --- a/prisma/seed.ts +++ b/prisma/seed.ts @@ -29,7 +29,8 @@ async function main() { update: {}, }); - if (await db.course.findMany()) { + const doCoursesExists = !!(await db.course.findMany()).length; + if (doCoursesExists) { console.error('DB is already seeded!'); process.exit(0); } From ec02cfac2eecf610cbdd9c2e98b891f8f5310127 Mon Sep 17 00:00:00 2001 From: devsargam Date: Mon, 1 Apr 2024 02:11:59 +0530 Subject: [PATCH 5/6] fix: admin enabled in dev mode --- src/app/admin/layout.tsx | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/app/admin/layout.tsx b/src/app/admin/layout.tsx index f21fe4708..94ac00a2b 100644 --- a/src/app/admin/layout.tsx +++ b/src/app/admin/layout.tsx @@ -13,6 +13,10 @@ export default async function AdminLayout({ return redirect('/signin'); } + if (process.env.LOCAL_CMS_PROVIDER) { + return <>{children} + } + if (!process.env.ADMINS?.split(',').includes(session.user.email!)) { return notFound(); } From a067e5eadf9fcfde5b2540fb5341b2823879cb50 Mon Sep 17 00:00:00 2001 From: Sargam Date: Mon, 1 Apr 2024 21:50:27 +0530 Subject: [PATCH 6/6] Update layout.tsx --- src/app/admin/layout.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/admin/layout.tsx b/src/app/admin/layout.tsx index 94ac00a2b..5c3f5b3f5 100644 --- a/src/app/admin/layout.tsx +++ b/src/app/admin/layout.tsx @@ -14,7 +14,7 @@ export default async function AdminLayout({ } if (process.env.LOCAL_CMS_PROVIDER) { - return <>{children} + return <>{children}; } if (!process.env.ADMINS?.split(',').includes(session.user.email!)) {