next-learn icon indicating copy to clipboard operation
next-learn copied to clipboard

Docs: `seed.js` should be `app/seed/routes.ts`

Open Punpun1643 opened this issue 5 months ago • 0 comments

Issue

Inside of /app, there's a folder called seed. Uncomment this file. This folder contains a Next.js Route Handler, called route.ts, that will be used to seed your database.

Here under route.ts, bcrypt package is used to hash users' passwords upon creation.

import bcrypt from 'bycrypt';
...

async function seedUsers() {
...
const insertedUsers = await Promise.all(
    users.map(async (user) => {
      const hashedPassword = await bcrypt.hash(user.password, 10); // bcrypt is used here
      return client.sql`
        INSERT INTO users (id, name, email, password)
        VALUES (${user.id}, ${user.name}, ${user.email}, ${hashedPassword})
        ON CONFLICT (id) DO NOTHING;
      `;
    }),
  );

}
  • However, under Chapter 15: Adding Authentication, the step Password Hashing metnioned

In your seed.js file, you used a package called bcrypt to hash the user's password before storing it in the database.

This is misleading, as there is no longer a seed.js file (apparently based on previous issues, this file was there in the past).

Proposed solution

Change seed.js to app/seed/routes.ts to reflect the current file structure accurately.

Punpun1643 avatar Sep 23 '24 14:09 Punpun1643