Skip to content

Commit

Permalink
Merge pull request #303 from devsargam/fix/dev-mode
Browse files Browse the repository at this point in the history
fix(dev): improve local development experience
  • Loading branch information
hkirat authored Apr 1, 2024
2 parents 02773ba + a067e5e commit 9157047
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 15 deletions.
47 changes: 32 additions & 15 deletions prisma/seed.ts
Original file line number Diff line number Diff line change
@@ -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: [
{
Expand Down
4 changes: 4 additions & 0 deletions src/app/admin/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
10 changes: 10 additions & 0 deletions src/lib/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,16 @@ export const authOptions = {
},
async authorize(credentials: any) {
try {
if (process.env.LOCAL_CMS_PROVIDER) {
return {
id: '1',
name: 'test',
email: '[email protected]',
token: await generateJWT({
id: '1',
}),
};
}
const hashedPassword = await bcrypt.hash(credentials.password, 10);

const userDb = await prisma.user.findFirst({
Expand Down
2 changes: 2 additions & 0 deletions src/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down

0 comments on commit 9157047

Please sign in to comment.