user creation and invites

This commit is contained in:
2025-06-24 16:31:13 -04:00
parent 23c8f468fe
commit a659401bde
32 changed files with 667 additions and 30 deletions

38
lib/email.ts Normal file
View File

@@ -0,0 +1,38 @@
import nodemailer from 'nodemailer'
const transporter = nodemailer.createTransport({
host: process.env.SMTP_HOST,
port: Number(process.env.SMTP_PORT),
secure: false,
auth: {
user: process.env.SMTP_USER,
pass: process.env.SMTP_PASS,
}
})
export async function sendInviteEmail({
to,
inviterName,
inviteUrl,
role,
}: {
to: string
inviterName: string
inviteUrl: string
role: string
}) {
const fromName = process.env.SMTP_FROM_NAME || 'Wedding Planner'
const fromEmail = process.env.SMTP_FROM_EMAIL || 'noreply@example.com'
await transporter.sendMail({
from: `"${fromName}" <${fromEmail}>`,
to,
subject: `${inviterName} invited you to join their wedding planner`,
html: `
<p>Hello!</p>
<p><strong>${inviterName}</strong> invited you to join their wedding planning space as a <strong>${role}</strong>.</p>
<p><a href="${inviteUrl}">Click here to accept your invite</a></p>
<p>This link will expire in 72 hours.</p>
`,
})
}

32
lib/invite.ts Normal file
View File

@@ -0,0 +1,32 @@
import { prisma } from './prisma';
import { randomBytes } from 'crypto';
export async function createInvite({
email,
role,
eventId
}: {
email: string
role: 'COUPLE' | 'PLANNER' | 'GUEST'
eventId?: string
}) {
const token = randomBytes(32).toString('hex');
const invite = await prisma.inviteToken.create({
data: {
email,
role,
token,
eventId,
expiresAt: new Date(Date.now() + 1000 * 60 * 60 * 24),
},
})
return invite
}
export async function verifyInvite(token:string) {
return await prisma.inviteToken.findUnique({
where: { token }
})
}

View File

@@ -1,4 +1,5 @@
import { prisma } from './prisma';
import bcrypt from 'bcrypt'
export const mutations = {
async createEvent(data: {
@@ -30,5 +31,30 @@ export const mutations = {
email: data.email,
},
});
}
},
async createUser({
username,
email,
password,
role,
}: {
username: string
email?: string
password: string
role: 'COUPLE' | 'PLANNER' | 'GUEST'
}) {
const hashedPassword = await bcrypt.hash(password, 10)
const user = await prisma.user.create({
data: {
username,
email: email || '',
password: hashedPassword,
role,
},
})
return user
},
};

View File

@@ -5,5 +5,18 @@ export const queries = {
const allEvents = await prisma.event.findMany()
console.log(allEvents)
return allEvents;
},
async singleEvent(id: string) {
const event = await prisma.event.findUnique({
where: { id },
include: {
creator: {
select: { id: true, email: true, name: true, role: true },
},
guests: true
}
})
return event
}
}