feat(tmp): invite link feature

This commit is contained in:
Levente Orban
2025-10-15 10:00:26 +02:00
parent f6b51232a7
commit c9c78d0ea6
18 changed files with 1199 additions and 164 deletions

View File

@@ -1,8 +1,9 @@
import { database } from '$lib/database/db';
import { events, rsvps } from '$lib/database/schema';
import { eq, asc } from 'drizzle-orm';
import { events, rsvps, inviteTokens } from '$lib/database/schema';
import { eq, asc, and } from 'drizzle-orm';
import { error, fail } from '@sveltejs/kit';
import type { PageServerLoad, Actions } from './$types';
import { isTokenValid } from '$lib/inviteTokenHelpers.js';
export const load: PageServerLoad = async ({ params, cookies }) => {
const eventId = params.id;
@@ -25,6 +26,16 @@ export const load: PageServerLoad = async ({ params, cookies }) => {
const event = eventData[0];
const eventRsvps = rsvpData;
// Check if this is an invite-only event
if (event.visibility === 'invite-only') {
// For invite-only events, check if user is the event creator
const userId = cookies.get('cactoideUserId');
if (event.userId !== userId) {
// User is not the creator, redirect to a message about needing invite
throw error(403, 'This event requires an invite link to view');
}
}
// Transform the data to match the expected interface
const transformedEvent = {
id: event.id,
@@ -85,6 +96,11 @@ export const actions: Actions = {
return fail(404, { error: 'Event not found' });
}
// Check if this is an invite-only event
if (eventData.visibility === 'invite-only') {
return fail(403, { error: 'This event requires an invite link to RSVP' });
}
// Get current RSVPs
const currentRSVPs = await database.select().from(rsvps).where(eq(rsvps.eventId, eventId));