Adds auth to dashboard using NextAuth (#173)

This commit is contained in:
Stephanie Dietz
2023-09-27 15:23:12 -05:00
committed by GitHub
parent 38725bc4e9
commit c478aa149b
12 changed files with 1765 additions and 44 deletions

View File

@@ -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();