mirror of
https://github.com/vercel/next-learn.git
synced 2026-07-09 06:55:12 +00:00
Adds auth to dashboard using NextAuth (#173)
This commit is contained in:
@@ -1,5 +1,49 @@
|
||||
const { sql } = require('@vercel/postgres');
|
||||
const { invoices, customers, revenue } = require('../app/lib/dummy-data.js');
|
||||
const {
|
||||
invoices,
|
||||
customers,
|
||||
revenue,
|
||||
users,
|
||||
} = require('../app/lib/dummy-data.js');
|
||||
const bcrypt = require('bcrypt');
|
||||
|
||||
async function seedUsers() {
|
||||
try {
|
||||
// Create the "invoices" table if it doesn't exist
|
||||
const createTable = await sql`
|
||||
CREATE TABLE IF NOT EXISTS users (
|
||||
id SERIAL PRIMARY KEY,
|
||||
name VARCHAR(255) NOT NULL,
|
||||
email TEXT NOT NULL UNIQUE,
|
||||
password TEXT NOT NULL
|
||||
);
|
||||
`;
|
||||
|
||||
console.log(`Created "users" table`);
|
||||
|
||||
// Insert data into the "users" table
|
||||
const insertedUsers = await Promise.all(
|
||||
users.map(async (user) => {
|
||||
const hashedPassword = await bcrypt.hash(user.password, 10);
|
||||
return sql`
|
||||
INSERT INTO users (id, name, email, password)
|
||||
VALUES (${user.id}, ${user.name}, ${user.email}, ${hashedPassword})
|
||||
ON CONFLICT (id) DO NOTHING;
|
||||
`;
|
||||
}),
|
||||
);
|
||||
|
||||
console.log(`Seeded ${insertedUsers.length} users`);
|
||||
|
||||
return {
|
||||
createTable,
|
||||
users: insertedUsers,
|
||||
};
|
||||
} catch (error) {
|
||||
console.error('Error seeding users:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
async function seedInvoices() {
|
||||
try {
|
||||
@@ -112,6 +156,7 @@ async function seedRevenue() {
|
||||
}
|
||||
|
||||
(async () => {
|
||||
await seedUsers();
|
||||
await seedCustomers();
|
||||
await seedInvoices();
|
||||
await seedRevenue();
|
||||
|
||||
Reference in New Issue
Block a user