diff --git a/prisma/seed.ts b/prisma/seed.ts index fd1bd7ac4..fe3ba0b86 100644 --- a/prisma/seed.ts +++ b/prisma/seed.ts @@ -1,23 +1,40 @@ 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: {}, }); + const doCoursesExists = !!(await db.course.findMany()).length; + if (doCoursesExists) { + console.error('DB is already seeded!'); + process.exit(0); + } + await db.course.createMany({ data: [ { diff --git a/src/app/admin/layout.tsx b/src/app/admin/layout.tsx index f21fe4708..5c3f5b3f5 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(); } diff --git a/src/lib/auth.ts b/src/lib/auth.ts index 11c1c7845..12d152129 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));