Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(dev): improve local development experience #303

Merged
merged 6 commits into from
Apr 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading